Class GeodeticCalculator


  • public class GeodeticCalculator
    extends Object
    Performs geodetic calculations on a sphere or an ellipsoid. This class computes the distance between two points, or conversely the point located at a given distance from another point when navigating in a given direction. The distance depends on the path (or track) on Earth surface connecting the two points. The track can be great circles (shortest path between two points) or rhumb lines (path with constant heading).

    This class uses the following information:

    • The start point, which is always considered valid after the first call to set­Start­Point(…). Its value can only be changed by another call to set­Start­Point(…).
    • One of the followings (the latest specified properties override other properties and determines what will be calculated):
    Algorithms and accuracy
    Geodetic­Calculator uses two set of formulas, depending if the figure of the Earth is a sphere or an ellipsoid. Publications relevant to this class are: Geodetic­Calculator aims for a positional accuracy of one centimetre. Azimuthal accuracy corresponds to an error of one centimetre at a distance of one kilometer, except for nearly antipodal points (less than 1° of longitude and latitude from antipode) and points close to the poles where the azimuthal errors are larger. Karney's GeographicLib should be used if better accuracy is desired. Apache SIS accuracy does not go as far as GeographicLib because the rest of Apache SIS library (map projections, etc.) aims for an one centimetre accuracy anyway.
    Limitations
    Current implementation can not compute the geodesics in some cases. In particular, calculation may fail for antipodal points on an ellipsoid. Karney's algorithm should cover those cases, but this Geodetic­Calculator implementation may not be sufficiently tuned. See SIS-467 for more information.
    Thread safety
    This class is not thread-safe. If geodetic calculations are needed in a multi-threads environment, then a distinct instance of Geodetic­Calculator needs to be created for each thread.
    Since:
    1.0

    Defined in the sis-referencing module

    • Method Detail

      • create

        public static GeodeticCalculator create​(CoordinateReferenceSystem crs)
        Constructs a new geodetic calculator expecting coordinates in the supplied CRS. All Geodetic­Calculator methods having a Position argument or return value will use that specified CRS. That CRS is the value returned by get­Position­CRS().

        Limitation: current implementation uses only spherical formulas. Implementation using ellipsoidal formulas will be provided in a future Apache SIS release.

        Parameters:
        crs - the reference system for the Position objects.
        Returns:
        a new geodetic calculator using the specified CRS.
      • getPositionCRS

        public CoordinateReferenceSystem getPositionCRS()
        Returns the Coordinate Reference System (CRS) in which Positions are represented, unless otherwise specified. This is the CRS of all Position instances returned by methods in this class. This is also the default CRS assumed by methods receiving a Position argument when the given position does not specify its CRS. This default CRS is specified at construction time. It is not necessarily geographic; it may be projected or geocentric.
        Returns:
        the default CRS for Position instances.
      • getGeographicCRS

        public GeographicCRS getGeographicCRS()
        Returns the coordinate reference system for all methods expecting (φ,λ) as double values. This CRS always has (latitude, longitude) axes, in that order and in degrees. The CRS may contain an additional axis for ellipsoidal height.
        Returns:
        the coordinate reference system of (φ,λ) coordinates.
      • getStartPoint

        public DirectPosition getStartPoint()
        Returns the starting point in the CRS specified at construction time. This method returns the last point given to a set­Start­Point(…) method, transformed to the position CRS.
        Returns:
        the starting point represented in the CRS specified at construction time.
        Throws:
        Illegal­State­Exception - if the start point has not yet been specified.
        Geodetic­Exception - if the coordinates can not be transformed to position CRS.
        See Also:
        get­End­Point()
      • setStartPoint

        public void setStartPoint​(Position point)
        Sets the starting point as coordinates in arbitrary reference system. This method transforms the given coordinates to geographic coordinates, then delegates to set­Start­Geographic­Point(double, double). If the given point is not associated to a Coordinate Reference System (CRS), then this method assumes the CRS specified at construction time.
        Parameters:
        point - the starting point in any coordinate reference system.
        Throws:
        Illegal­Argument­Exception - if the given coordinates can not be transformed.
        See Also:
        set­End­Point(Position)
      • setEndPoint

        public void setEndPoint​(Position position)
        Sets the destination as coordinates in arbitrary reference system. This method transforms the given coordinates to geographic coordinates, then delegates to set­End­Geographic­Point(double, double). If the given point is not associated to a Coordinate Reference System (CRS), then this method assumes the CRS specified at construction time.
        Parameters:
        position - the destination (end point) in any coordinate reference system.
        Throws:
        Illegal­Argument­Exception - if the given coordinates can not be transformed.
        See Also:
        set­Start­Point(Position)
      • getStartingAzimuth

        public double getStartingAzimuth()
        Returns or computes the angular heading at the starting point of a geodesic path. Azimuth is relative to geographic North with values increasing clockwise. This method returns the azimuth normalized to [-180 … +180]° range given in last call to set­Starting­Azimuth(double) method, unless the set­End­Point(…) method has been invoked more recently. In the later case, the azimuth will be computed from the start point and the current end point.
        Returns:
        the azimuth in degrees from -180° to +180°. 0° is toward North and values are increasing clockwise.
        Throws:
        Illegal­State­Exception - if the end point, azimuth or distance have not been set.
        Geodetic­Exception - if the azimuth can not be computed.
      • setStartingAzimuth

        public void setStartingAzimuth​(double azimuth)
        Sets the angular heading at the starting point of a geodesic path. Azimuth is relative to geographic North with values increasing clockwise. The ending azimuth, end point and rhumb line length will be updated as an effect of this method call.
        Parameters:
        azimuth - the starting azimuth in degrees, with 0° toward north and values increasing clockwise.
        See Also:
        set­Geodesic­Distance(double)
      • getEndingAzimuth

        public double getEndingAzimuth()
        Computes the angular heading at the ending point of a geodesic path. Azimuth is relative to geographic North with values increasing clockwise. This method computes the azimuth from the current start point and end point, or from start point and the current starting azimuth and geodesic distance.
        Returns:
        the azimuth in degrees from -180° to +180°. 0° is toward North and values are increasing clockwise.
        Throws:
        Illegal­State­Exception - if the destination point, azimuth or distance have not been set.
        Geodetic­Exception - if the azimuth can not be computed.
      • getConstantAzimuth

        public double getConstantAzimuth()
        Computes the angular heading of a rhumb line path. Azimuth is relative to geographic North with values increasing clockwise.
        Returns:
        the azimuth in degrees from -180° to +180°. 0° is toward North and values are increasing clockwise.
        Throws:
        Illegal­State­Exception - if the start point or end point has not been set.
        Geodetic­Exception - if the azimuth can not be computed.
      • getRhumblineLength

        public double getRhumblineLength()
        Returns or computes the length of rhumb line (part of constant heading) from start point to end point. This is sometime called "loxodrome". This is not the shortest path between two points. The rhumb line distance may be up to 50% longer than the geodesic distance.
        Returns:
        length of rhumb line in the unit of measurement given by get­Distance­Unit().
        Throws:
        Illegal­State­Exception - if a point has not been set.
      • createGeodesicPath2D

        public Shape createGeodesicPath2D​(double tolerance)
        Creates an approximation of the geodesic track from start point to end point as a Java2D object. The coordinates are expressed in the coordinate reference system specified at creation time. The approximation uses linear, quadratic or cubic Bézier curves. The returned path has the following characteristics:
        1. The first point is get­Start­Point().
        2. The beginning of the curve (more specifically, the tangent at starting point) is oriented toward the direction given by getStartingAzimuth(), adjusted for the map projection (if any) deformation at that location.
        3. The point B(½) in the middle of the Bézier curve is a point of the geodesic path.
        4. The end of the curve (more specifically, the tangent at ending point) is oriented toward the direction given by getEndingAzimuth(), adjusted for the map projection (if any) deformation at that location.
        5. The last point is get­End­Point(), potentially with 360° added or subtracted to the longitude.
        This method tries to stay within the given tolerance threshold of the geodesic track. The tolerance parameter should not be too small for avoiding creation of unreasonably long chain of Bézier curves. For example a value of 1/10 of geodesic length may be sufficient.
        Note: this method depends on the presence of java​.desktop module. This constraint may be addressed in a future Apache SIS version (see SIS-453). The "2D" suffix in the method name represents this relationship with Java2D. The create­Geodesic­Path(…) method name (without suffix) is reserved for a future version using ISO curves instead.
        Parameters:
        tolerance - maximal error between the approximated curve and actual geodesic track in the units of measurement given by get­Distance­Unit(). This is approximate; the actual errors may vary around that value.
        Returns:
        an approximation of geodesic track as Bézier curves in a Java2D object.
        Throws:
        Illegal­State­Exception - if some required properties have not been specified.
        Geodetic­Exception - if some coordinates can not be computed.
      • createGeodesicCircle2D

        public Shape createGeodesicCircle2D​(double tolerance)
        Creates an approximation of the curve at a constant geodesic distance around the start point. The returned shape is circlelike with the start point in its center. The coordinates are expressed in the coordinate reference system specified at creation time. The approximation uses cubic Bézier curves.
        Note: some authors define geodesic circle as the curve which enclose the maximum area for a given perimeter. This method adopts a different definition, the locus of points at a fixed geodesic distance from center point.
        This method tries to stay within the given tolerance threshold of the geodesic track. The tolerance parameter should not be too small for avoiding creation of unreasonably long chain of Bézier curves. For example a value of 1/10 of geodesic length may be sufficient.
        Note: this method depends on the presence of java​.desktop module. This constraint may be addressed in a future Apache SIS version (see SIS-453). The "2D" suffix in the method name represents this relationship with Java2D. The create­Geodesic­Circle(…) method name (without suffix) is reserved for a future version using ISO curves instead.
        Parameters:
        tolerance - maximal error in the units of measurement given by get­Distance­Unit(). This is approximate; the actual errors may vary around that value.
        Returns:
        an approximation of circular region as a Java2D object.
        Throws:
        Illegal­State­Exception - if some required properties have not been specified.
        Geodetic­Exception - if some coordinates can not be computed.
      • toString

        public String toString()
        Returns a string representation of start point, end point, azimuths and distance. The text representation is implementation-specific and may change in any future version. Current implementation is like below:
        Coordinate reference system: Unspecified datum based upon the GRS 1980 Authalic Sphere
        ┌─────────────┬─────────────────┬──────────────────┬─────────────┐
        │             │    Latitude     │    Longitude     │   Azimuth   │
        │ Start point │  9°39′06.1120″N │ 132°37′37.1248″W │  -17°10′37″ │
        │ End point   │ 70°32′45.0206″N │ 109°50′05.0533″E │ -119°03′12″ │
        └─────────────┴─────────────────┴──────────────────┴─────────────┘
        Geodesic distance: 9,967,530.74 m
        Overrides:
        to­String in class Object
        Returns:
        a string representation of this calculator state.