Class DataLocation

java.lang.Object
noaa.coastwatch.util.DataLocation
All Implemented Interfaces:
Cloneable

public class DataLocation extends Object implements 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

    Constructors
    Modifier
    Constructor
    Description
    protected
    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 Type
    Method
    Description
    Gets the nearest data location with whole integer coordinates greater than this location.
     
    protected static DataLocation
    create(double[] coords)
    Creates a new data location without cloning.
    boolean
     
    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
    Gets the data location dimension rank.
    int
     
    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
    Tests if this data location is contained between a minimum and a maximum.
    boolean
    Checks if this data location is invalid.
    boolean
    Checks if this data location is valid.
    void
    Marks this location as invalid.
    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
    Sets the data location coordinates from another location.
     
    Transforms this data location using an affine transform.
    void
    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.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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

      public String format(boolean doRound)
      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

      public DataLocation round()
      Gets the nearest data location with whole integer coordinates.
      Returns:
      the nearest data location.
    • floor

      public DataLocation floor()
      Gets the nearest data location with whole integer coordinates less than this location.
      Returns:
      the nearest lesser integer data location.
    • ceil

      public DataLocation ceil()
      Gets the nearest data location with whole integer coordinates greater than this location.
      Returns:
      the nearest greater integer data location.
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • 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

      public void setCoords(DataLocation source)
      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

      public boolean isContained(DataLocation min, DataLocation max)
      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

      public DataLocation truncate(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.
      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

      public String toString()
      Overrides:
      toString in class Object
    • transformInPlace

      public void transformInPlace(AffineTransform affine)
      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

      public DataLocation transform(AffineTransform affine)
      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

      public DataLocation translate(double trans0, double trans1)
      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

      public DataLocation translate(double trans0, double trans1, DataLocation outputLoc)
      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

      public DataLocation translate(double[] trans)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • create

      protected static DataLocation create(double[] coords)
      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

      public boolean increment(int[] stride, DataLocation start, DataLocation end)
      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()
      Overrides:
      hashCode in class Object