Package noaa.coastwatch.util
Class DataLocation
java.lang.Object
noaa.coastwatch.util.DataLocation
- All Implemented Interfaces:
Cloneable
A data location represents a set of coordinates that uniquely
identify a data value position within some N-dimensional space.
- Since:
- 3.1.1
- Author:
- Peter Hollemans
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructs a new data location.DataLocation
(double coord0) Constructs a 1D data location from the specified coordinates.DataLocation
(double[] coords) Constructs a data location from the specified coordinates.DataLocation
(double coord0, double coord1) Constructs a 2D data location from the specified coordinates.DataLocation
(int rank) Constructs a data location with the specified rank.DataLocation
(int index, int[] dims) Creates a data location from an integer index and a set of dimensions. -
Method Summary
Modifier and TypeMethodDescriptionceil()
Gets the nearest data location with whole integer coordinates greater than this location.clone()
protected static DataLocation
create
(double[] coords) Creates a new data location without cloning.boolean
floor()
Gets the nearest data location with whole integer coordinates less than this location.format
(boolean doRound) Gets a formatted string for this location.double
get
(int index) Gets one data location coordinate value.double[]
Gets the data location coordinates as an array.double[]
getCoords
(double[] coordsCopy) Gets the data location coordinates as an array.int
getIndex
(int[] dims) Translates a data location into an integer index.int
getRank()
Gets the data location dimension rank.int
hashCode()
boolean
increment
(int[] stride, int[] dims) Increments this location by the specified stride.boolean
increment
(int[] stride, DataLocation start, DataLocation end) Increments this location by the specified stride.boolean
isContained
(int[] dims) Tests if this data location is contained within the specified dimensions.boolean
isContained
(DataLocation min, DataLocation max) Tests if this data location is contained between a minimum and a maximum.boolean
Checks if this data location is invalid.boolean
isValid()
Checks if this data location is valid.void
Marks this location as invalid.round()
Gets the nearest data location with whole integer coordinates.void
set
(int index, double coord) Sets one data location coordinate value.void
setCoords
(double[] coords) Sets the data location coordinates from an array.void
setCoords
(int[] coords) Sets the data location coordinates from an array.void
setCoords
(DataLocation source) Sets the data location coordinates from another location.toString()
transform
(AffineTransform affine) Transforms this data location using an affine transform.void
transformInPlace
(AffineTransform affine) Transforms this data location in place using an affine transform.translate
(double[] trans) Performs a translation on this data location.translate
(double trans0, double trans1) Performs a 2D translation on this data location.translate
(double trans0, double trans1, DataLocation outputLoc) Performs a 2D translation on this data location.truncate
(int[] dims) Truncates the data location to the nearest edge.void
truncateInPlace
(int[] dims) Truncates the data location to the nearest edge.
-
Constructor Details
-
DataLocation
public DataLocation(int rank) Constructs a data location with the specified rank. All coordinates are initialized to 0.- Parameters:
rank
- the data location rank.
-
DataLocation
public DataLocation(double coord0) Constructs a 1D data location from the specified coordinates.- Parameters:
coord0
- the 0 index coordinate value.
-
DataLocation
public DataLocation(double coord0, double coord1) Constructs a 2D data location from the specified coordinates.- Parameters:
coord0
- the 0 index coordinate value.coord1
- the 1 index coordinate value.
-
DataLocation
public DataLocation(double[] coords) Constructs a data location from the specified coordinates.- Parameters:
coords
- the data location coordinates.
-
DataLocation
public DataLocation(int index, int[] dims) Creates a data location from an integer index and a set of dimensions.- Parameters:
index
- the integer index.dims
- the dimension lengths along each dimension.
-
DataLocation
protected DataLocation()Constructs a new data location.
-
-
Method Details
-
format
Gets a formatted string for this location.- Parameters:
doRound
- the rounding flag, true if rounding to the nearest integer coordinate is desired.- Returns:
- the formatted location string.
-
round
Gets the nearest data location with whole integer coordinates.- Returns:
- the nearest data location.
-
floor
Gets the nearest data location with whole integer coordinates less than this location.- Returns:
- the nearest lesser integer data location.
-
ceil
Gets the nearest data location with whole integer coordinates greater than this location.- Returns:
- the nearest greater integer data location.
-
clone
-
get
public double get(int index) Gets one data location coordinate value.- Parameters:
index
- the dimension index.- Returns:
- the coordinate value or Double.NaN if the index in invalid.
-
set
public void set(int index, double coord) Sets one data location coordinate value.- Parameters:
index
- the dimension index.coord
- the coordinate value.
-
getCoords
public double[] getCoords(double[] coordsCopy) Gets the data location coordinates as an array.- Parameters:
coordsCopy
- the array of coordinates to fill, or null to create a new array.- Returns:
- the array of coordinate values, one per dimension.
- Since:
- 3.3.1
-
getCoords
public double[] getCoords()Gets the data location coordinates as an array.- Returns:
- the array of coordinate values, one per dimension.
-
setCoords
public void setCoords(double[] coords) Sets the data location coordinates from an array.- Parameters:
coords
- the array of coordinate values, one per dimension. If the array does not match the location rank, no operation is performed.
-
setCoords
public void setCoords(int[] coords) Sets the data location coordinates from an array.- Parameters:
coords
- the array of coordinate values, one per dimension. If the array does not match the location rank, no operation is performed.
-
setCoords
Sets the data location coordinates from another location.- Parameters:
source
- the source coordinate data location. If the source location does not match in rank, no operation is performed.
-
getRank
public int getRank()Gets the data location dimension rank. -
isContained
Tests if this data location is contained between a minimum and a maximum. Containment means that each coordinate is bounded below by the min and above by the max at each dimension.- Parameters:
min
- the minimum location.max
- the maximum location.- Returns:
- true if the location is contained or false if not. If the min and max do not match rank with this location, false is returned.
-
isContained
public boolean isContained(int[] dims) Tests if this data location is contained within the specified dimensions. The test checks if this location is in the range [0..dims[i]-1] for all i.- Parameters:
dims
- the dimensions for testing.- Returns:
- true if the location is contained or false if not. If the dimensions do not match rank with this location, false is returned.
-
truncate
Truncates the data location to the nearest edge. If the location has any components outside [0..n-1] for each dimension size n, then they are truncated to the nearest dimension bound.- Parameters:
dims
- the dimension sizes.- Returns:
- the truncated data location.
-
truncateInPlace
public void truncateInPlace(int[] dims) Truncates the data location to the nearest edge. If the location has any components outside [0..n-1] for each dimension size n, then they are truncated to the nearest dimension bound.- Parameters:
dims
- the dimension sizes.- Since:
- 3.4.1
-
getIndex
public int getIndex(int[] dims) Translates a data location into an integer index. If the data location has fractional coordinates, they are rounded prior to calculating the index.- Parameters:
dims
- the dimension lengths along each dimension.- Returns:
- a unique index. If the data coordinate is out of bounds, a -1 is returned. If the dimensions do not match rank with this location, -1 is returned.
-
toString
-
transformInPlace
Transforms this data location in place using an affine transform. This operation can only be applied to a 2D location.- Parameters:
affine
- the affine transform to use.- Since:
- 3.3.1
-
transform
Transforms this data location using an affine transform. This operation can only be applied to a 2D location.- Parameters:
affine
- the affine transform to use.- Returns:
- the transformed data location. If this location is not 2D, no transformation is performed and a clone of this location is returned.
-
translate
Performs a 2D translation on this data location.- Parameters:
trans0
- the translation for index 0.trans1
- the translation for index 1.- Returns:
- the translated data location. If this location rank is not 2, no operation is performed and a clone of this location is returned.
-
translate
Performs a 2D translation on this data location.- Parameters:
trans0
- the translation for index 0.trans1
- the translation for index 1.outputLoc
- the output translated data location. This location and the output data location are assumed to both be 2D. It is safe to pass this location as the output location, in which case the translation is performed in-place.- Since:
- 3.4.1
-
translate
Performs a translation on this data location.- Parameters:
trans
- the translation array. Each component of the translation array is added to the coordinate values.- Returns:
- the translated data location. If the translation array rank does not match this location rank, no operation is performed and a clone of this location is returned.
-
equals
-
create
Creates a new data location without cloning. -
isValid
public boolean isValid()Checks if this data location is valid.- Returns:
- true if the location is valid or false if not. An invalid data location is normally used as a flag for a computation that has failed.
- See Also:
-
isInvalid
public boolean isInvalid()Checks if this data location is invalid.- Returns:
- true if the location is invalid or false if not. An invalid data location is normally used as a flag for a computation that has failed.
- See Also:
-
markInvalid
public void markInvalid()Marks this location as invalid. Subsequent calls to check for validity will reflect the new state.- Since:
- 3.3.1
- See Also:
-
increment
public boolean increment(int[] stride, int[] dims) Increments this location by the specified stride. The data location is incremented at only one dimension at a time until the bounds are hit for that dimension, then the next dimension is incremented. This has the effect of subsampling the locations at the specified stride intervals along each dimension.- Parameters:
stride
- the data location stride in each dimension.dims
- the dimension lengths along each dimension.- Returns:
- true if the increment is successful, false otherwise.
- See Also:
-
increment
Increments this location by the specified stride. The data location is incremented at only one dimension at a time until the bounds are hit for that dimension, then the next dimension is incremented. This has the effect of subsampling the locations at the specified stride intervals along each dimension. The increment takes into account the data location window.- Parameters:
stride
- the data location stride in each dimension.start
- the data location window start.end
- the data location window end.- Returns:
- true if the increment is successful, false otherwise.
- See Also:
-
hashCode
public int hashCode()
-