Class ProjCoordinate

java.lang.Object
org.locationtech.proj4j.ProjCoordinate
All Implemented Interfaces:
Serializable

public class ProjCoordinate extends Object implements Serializable
Stores a the coordinates for a position defined relative to some CoordinateReferenceSystem. The coordinate is defined via X, Y, and optional Z ordinates. Provides utility methods for comparing the ordinates of two positions and for creating positions from Strings/storing positions as strings.

The primary use of this class is to represent coordinate values which are to be transformed by a CoordinateTransform.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    static String
     
    double
    The X ordinate for this point.
    double
    The Y ordinate for this point.
    double
    The Z ordinate for this point.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a ProjCoordinate with default ordinate values.
    ProjCoordinate(double argX, double argY)
    Creates a ProjCoordinate using the provided double parameters.
    ProjCoordinate(double argX, double argY, double argZ)
    Creates a ProjCoordinate using the provided double parameters.
    ProjCoordinate(String argToParse)
    Create a ProjCoordinate by parsing a String in the same format as returned by the toString method defined by this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    areXOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
    Returns a boolean indicating if the X ordinate value of the ProjCoordinate provided as an ordinate is equal to the X ordinate value of this ProjCoordinate.
    boolean
    areYOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
    Returns a boolean indicating if the Y ordinate value of the ProjCoordinate provided as an ordinate is equal to the Y ordinate value of this ProjCoordinate.
    boolean
    areZOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
    Returns a boolean indicating if the Z ordinate value of the ProjCoordinate provided as an ordinate is equal to the Z ordinate value of this ProjCoordinate.
    void
     
    boolean
    equals(Object other)
     
    int
    Gets a hashcode for this coordinate.
    private static int
    hashCode(double x)
    Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"
    boolean
    Indicates if this ProjCoordinate has valid X ordinate and Y ordinate values.
    boolean
     
    void
    setValue(double x, double y)
    Sets the value of this coordinate to be equal to the given ordinates.
    void
    setValue(double x, double y, double z)
    Sets the value of this coordinate to be equal to the given ordinates.
    void
    Sets the value of this coordinate to be equal to the given coordinate's ordinates.
    Returns a string representing the ProjPoint in the format: [X Y] or [X, Y, Z].
    Returns a string representing the ProjPoint in the format: ProjCoordinate[X Y Z].

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DECIMAL_FORMAT_PATTERN

      public static String DECIMAL_FORMAT_PATTERN
    • DECIMAL_FORMAT

      public static DecimalFormat DECIMAL_FORMAT
    • x

      public double x
      The X ordinate for this point.

      Note: This member variable can be accessed directly. In the future this direct access should be replaced with getter and setter methods. This will require refactoring of the Proj4J code base.

    • y

      public double y
      The Y ordinate for this point.

      Note: This member variable can be accessed directly. In the future this direct access should be replaced with getter and setter methods. This will require refactoring of the Proj4J code base.

    • z

      public double z
      The Z ordinate for this point. If this variable has the value Double.NaN then this coordinate does not have a Z value.

      Note: This member variable can be accessed directly. In the future this direct access should be replaced with getter and setter methods. This will require refactoring of the Proj4J code base.

  • Constructor Details

    • ProjCoordinate

      public ProjCoordinate()
      Creates a ProjCoordinate with default ordinate values.
    • ProjCoordinate

      public ProjCoordinate(double argX, double argY, double argZ)
      Creates a ProjCoordinate using the provided double parameters. The first double parameter is the x ordinate (or easting), the second double parameter is the y ordinate (or northing), and the third double parameter is the z ordinate (elevation or height).

      Valid values should be passed for all three (3) double parameters. If you want to create a horizontal-only point without a valid Z value, use the constructor defined in this class that only accepts two (2) double parameters.

      See Also:
    • ProjCoordinate

      public ProjCoordinate(double argX, double argY)
      Creates a ProjCoordinate using the provided double parameters. The first double parameter is the x ordinate (or easting), the second double parameter is the y ordinate (or northing). This constructor is used to create a "2D" point, so the Z ordinate is automatically set to Double.NaN.
    • ProjCoordinate

      public ProjCoordinate(String argToParse)
      Create a ProjCoordinate by parsing a String in the same format as returned by the toString method defined by this class.
      Parameters:
      argToParse - the string to parse
  • Method Details

    • setValue

      public void setValue(ProjCoordinate p)
      Sets the value of this coordinate to be equal to the given coordinate's ordinates.
      Parameters:
      p - the coordinate to copy
    • setValue

      public void setValue(double x, double y)
      Sets the value of this coordinate to be equal to the given ordinates. The Z ordinate is set to NaN.
      Parameters:
      x - the x ordinate
      y - the y ordinate
    • setValue

      public void setValue(double x, double y, double z)
      Sets the value of this coordinate to be equal to the given ordinates.
      Parameters:
      x - the x ordinate
      y - the y ordinate
      z - the z ordinate
    • clearZ

      public void clearZ()
    • areXOrdinatesEqual

      public boolean areXOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
      Returns a boolean indicating if the X ordinate value of the ProjCoordinate provided as an ordinate is equal to the X ordinate value of this ProjCoordinate. Because we are working with floating point numbers the ordinates are considered equal if the difference between them is less than the specified tolerance.
    • areYOrdinatesEqual

      public boolean areYOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
      Returns a boolean indicating if the Y ordinate value of the ProjCoordinate provided as an ordinate is equal to the Y ordinate value of this ProjCoordinate. Because we are working with floating point numbers the ordinates are considered equal if the difference between them is less than the specified tolerance.
    • areZOrdinatesEqual

      public boolean areZOrdinatesEqual(ProjCoordinate argToCompare, double argTolerance)
      Returns a boolean indicating if the Z ordinate value of the ProjCoordinate provided as an ordinate is equal to the Z ordinate value of this ProjCoordinate. Because we are working with floating point numbers the ordinates are considered equal if the difference between them is less than the specified tolerance.

      If both Z ordinate values are Double.NaN this method will return true. If one Z ordinate value is a valid double value and one is Double.Nan, this method will return false.

    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Gets a hashcode for this coordinate.
      Overrides:
      hashCode in class Object
      Returns:
      a hashcode for this coordinate
    • hashCode

      private static int hashCode(double x)
      Computes a hash code for a double value, using the algorithm from Joshua Bloch's book Effective Java"
      Returns:
      a hashcode for the double value
    • toString

      public String toString()
      Returns a string representing the ProjPoint in the format: ProjCoordinate[X Y Z].

      Example:

          ProjCoordinate[6241.11 5218.25 12.3]
       
      Overrides:
      toString in class Object
    • toShortString

      public String toShortString()
      Returns a string representing the ProjPoint in the format: [X Y] or [X, Y, Z]. Z is not displayed if it is NaN.

      Example:

                [6241.11, 5218.25, 12.3]
       
    • hasValidZOrdinate

      public boolean hasValidZOrdinate()
    • hasValidXandYOrdinates

      public boolean hasValidXandYOrdinates()
      Indicates if this ProjCoordinate has valid X ordinate and Y ordinate values. Values are considered invalid if they are Double.NaN or positive/negative infinity.