Class PlanitJtsCrsUtils


  • public class PlanitJtsCrsUtils
    extends Object
    General geographic JTS utilities that rely on a known Coordinate Reference system (CRS). Uses geodetic distance when possible. In case the CRS is not based on an ellipsoid (2d plane) it will simply compute the distance between coordinates using Pythagoras with the unit distance in meters, consistent with the CartesianAuthorityFactory.GENERIC_2D It is assumed that x coordinate refers to latitude and y coordinate refers to longitude
    Author:
    markr
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.opengis.referencing.crs.CoordinateReferenceSystem CARTESIANCRS
      In absence of a geographic crs we can also use cartesian: GENERIC_2D
      protected org.opengis.referencing.crs.CoordinateReferenceSystem crs
      the crs to use
      static org.geotools.referencing.crs.DefaultGeographicCRS DEFAULT_GEOGRAPHIC_CRS
      Default Coordinate Reference System: WGS84
      protected org.geotools.referencing.GeodeticCalculator geoCalculator
      geodetic calculator to use in tandem with the used CRS
      protected static org.locationtech.jts.geom.GeometryFactory jtsGeometryFactory
      jts geometry factory, jts geometry differs from opengis implementation by not carrying the crs and being more lightweight
    • Constructor Summary

      Constructors 
      Constructor Description
      PlanitJtsCrsUtils()
      Constructor Uses default coordinate reference system
      PlanitJtsCrsUtils​(org.opengis.referencing.crs.CoordinateReferenceSystem coordinateReferenceSystem)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.locationtech.jts.geom.Envelope createBoundingBox​(double centrePointX, double centrePointY, double lengthMeters)
      create a square bounding box envelope instance based on the passed in reference point and length in meters of each of the legs, with the point residing in the middle, it is expected the locations (when no cartesian) are in LAT/LONG regardless of the transformation of the underlying CRS
      org.locationtech.jts.geom.Envelope createBoundingBox​(double minX, double minY, double maxX, double maxY, double lengthMeters)
      create a square bounding box envelope instance based on the passed in bounding box coordinates and buffer length in meters resulting in a larger bounding box returned, it is expected the locations (when no cartesian) are in lat/long regardless of the transformation of the underlying CRS
      org.locationtech.jts.geom.Envelope createBoundingBox​(org.locationtech.jts.geom.Envelope boundingBox, double lengthMeters)
      create a square bounding box envelope instance based on an existing envelope bounding box and and buffer length in meters resulting in a larger bounding box returned, it is expected the locations (when no cartesian) are in lat/long regardless of the transformation * of the underlying CRS
      org.locationtech.jts.geom.LineSegment createExtendedLineSegment​(org.locationtech.jts.geom.LineSegment source, double extensionInMeters, boolean extendStart, boolean extendEnd)
      extend the given line segment in one or two directions with a given distance in meters.
      double getAzimuthInDegrees​(org.locationtech.jts.geom.Coordinate coordinate1, org.locationtech.jts.geom.Coordinate coordinate2, boolean zeroTo360)
      Collect the azimuth heading between the two coordinates (lat/long) in decimal degrees
      Double getAzimuthInDegrees​(org.opengis.geometry.coordinate.Position position1, org.opengis.geometry.coordinate.Position position2, boolean zeroTo360)
      Collect the azimuth heading between the two positions (in user CRS) in decimal degrees, from location 1 to location 2
      double getClosestDistanceInMeters​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.Geometry geometry)
      find the closest distance in meters from the point to the geometry.
      double getClosestDistanceInMetersMultiLineString​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.MultiLineString geometry)
      find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
      double getClosestDistanceInMetersToPolygon​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.Polygon geometry)
      find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
      double getClosestExistingCoordinateDistanceInMeters​(org.locationtech.jts.geom.Coordinate coord, org.locationtech.jts.geom.Geometry geometry)
      find the distance between the closest coordinate on the geometry's coordinates.
      org.locationtech.jts.geom.Coordinate getClosestExistingCoordinateToPoint​(org.locationtech.jts.geom.Coordinate coord, org.locationtech.jts.geom.Geometry geometry)
      find the coordinate on the geometry with the closest distance to the reference point.
      <T extends org.locationtech.jts.geom.LineString>
      org.locationtech.jts.geom.Coordinate
      getClosestExistingLineStringCoordinateToGeometry​(org.locationtech.jts.geom.Geometry referenceGeometry, T lineString)
      Find the coordinate on the line string with the closest distance to the reference referenceGeometry.
      <T extends org.locationtech.jts.geom.LineString>
      org.locationtech.jts.geom.Coordinate
      getClosestExistingLineStringCoordinateToGeometry​(org.locationtech.jts.geom.Geometry referenceGeometry, T lineString, int startIndex, int endIndex)
      Find the coordinate on the line string with the closest distance to the reference referenceGeometry.
      org.locationtech.jts.linearref.LinearLocation getClosestGeometryExistingCoordinateToProjectedLinearLocationOnLineString​(org.locationtech.jts.geom.Geometry referenceGeometry, org.locationtech.jts.geom.LineString linearGeometry)
      find the closest location from any existing coordinate of the reference geometry to the line string geometry as a linear location.
      org.locationtech.jts.geom.Coordinate getClosestPojectedCoordinateOnPolygon​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.Polygon polygon)
      find the closest location from the reference coordinate to the polygon expressed as a linear location.
      org.locationtech.jts.geom.Coordinate getClosestProjectedCoordinateOnGeometry​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.Geometry geometry)
      find the closest projected coordinate from the reference point to the geometry.
      org.locationtech.jts.geom.Coordinate getClosestProjectedCoordinateOnLineString​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.LineString lineString)
      find the closest projected coordinate from the reference point to the line string.
      double getClosestProjectedDistanceInMetersToLineString​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.LineString geometry)
      find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
      org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnGeometry​(org.locationtech.jts.geom.Coordinate reference, org.locationtech.jts.geom.Geometry geometry)
      find the closest location from the reference point to the geometry expressed as a linear location.
      org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnLineString​(org.locationtech.jts.geom.Coordinate referenceCoordinate, org.locationtech.jts.geom.LineString lineString)
      Find the closest location from the reference coordinate to the line string expressed as a linear location.
      org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnPolygon​(org.locationtech.jts.geom.Coordinate referenceCoordinate, org.locationtech.jts.geom.Polygon polygon)
      Find the closest location from the reference coordinate to the polygon expressed as a linear location.
      org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
      collect the crs used by this instance of the utils class
      double getDistanceInKilometres​(Vertex vertex1, Vertex vertex2)
      Compute the distance in kilometres between two vertices assuming the positions are set and based on the same crs as registered on this class instance
      double getDistanceInKilometres​(org.locationtech.jts.geom.LineString geometry)
      Compute the length of the line string by traversing all nodes and computing the segment by segment distances TODO: find out if a faster way is possible
      double getDistanceInKilometres​(org.locationtech.jts.geom.Point startPosition, org.locationtech.jts.geom.Point endPosition)
      Compute the distance in kilometres between two positions assuming the positions are provided in the same crs as registered on this class instance
      double getDistanceInMetres​(org.locationtech.jts.geom.Coordinate startCoordinate, org.locationtech.jts.geom.Coordinate endCoordinate)
      Compute the distance in metres between two (JTS) coordinates assuming the positions are provided in the same crs as registered on this class instance
      double getDistanceInMetres​(org.locationtech.jts.geom.Point startPosition, org.locationtech.jts.geom.Point endPosition)
      Compute the distance in metres between two (JTS) points assuming the positions are provided in the same crs as registered on this class instance
      boolean isDistanceWithinMetres​(org.locationtech.jts.geom.Coordinate startCoordinate, org.locationtech.jts.geom.Coordinate endCoordinate, double maxDistanceMeters)
      Determine if the distance in metres between two (JTS) coordinates (assuming the positions are provided in the same crs as registered on this class instance) is within the given distance
      boolean isDistanceWithinMetres​(org.locationtech.jts.geom.Point startPosition, org.locationtech.jts.geom.Point endPosition, double maxDistanceMeters)
      Determine if the distance in metres between two (JTS) coordinates (assuming the positions are provided in the same crs as registered on this class instance) is within the given distance
      boolean isGeometryLeftOf​(org.locationtech.jts.geom.Geometry geometry, org.locationtech.jts.geom.Coordinate coordA, org.locationtech.jts.geom.Coordinate coordB)
      Verify if the provided geometry resides left of the line defined from coordA to coordB.
      boolean isGeometryNearBoundingBox​(org.locationtech.jts.geom.Geometry geometry, org.locationtech.jts.geom.Envelope boundingBox, double maxDistanceMeters)
      Verify if any existing coordinate on the passed in geometry is within the maximum provided distance of the also provided bounding box
      org.opengis.geometry.DirectPosition toDirectPosition​(org.locationtech.jts.geom.Coordinate coordinate)
      extract direct position from coordinate
      org.opengis.geometry.DirectPosition toDirectPosition​(org.locationtech.jts.geom.Point point)
      extract direct position from point
    • Field Detail

      • crs

        protected final org.opengis.referencing.crs.CoordinateReferenceSystem crs
        the crs to use
      • geoCalculator

        protected final org.geotools.referencing.GeodeticCalculator geoCalculator
        geodetic calculator to use in tandem with the used CRS
      • jtsGeometryFactory

        protected static final org.locationtech.jts.geom.GeometryFactory jtsGeometryFactory
        jts geometry factory, jts geometry differs from opengis implementation by not carrying the crs and being more lightweight
      • DEFAULT_GEOGRAPHIC_CRS

        public static final org.geotools.referencing.crs.DefaultGeographicCRS DEFAULT_GEOGRAPHIC_CRS
        Default Coordinate Reference System: WGS84
      • CARTESIANCRS

        public static final org.opengis.referencing.crs.CoordinateReferenceSystem CARTESIANCRS
        In absence of a geographic crs we can also use cartesian: GENERIC_2D
    • Constructor Detail

      • PlanitJtsCrsUtils

        public PlanitJtsCrsUtils()
        Constructor Uses default coordinate reference system
      • PlanitJtsCrsUtils

        public PlanitJtsCrsUtils​(org.opengis.referencing.crs.CoordinateReferenceSystem coordinateReferenceSystem)
        Constructor
        Parameters:
        coordinateReferenceSystem - OpenGIS CoordinateReferenceSystem object containing geometry
    • Method Detail

      • getClosestExistingCoordinateDistanceInMeters

        public double getClosestExistingCoordinateDistanceInMeters​(org.locationtech.jts.geom.Coordinate coord,
                                                                   org.locationtech.jts.geom.Geometry geometry)
        find the distance between the closest coordinate on the geometry's coordinates. Note that this is likely NOT the closest point to the geometry as this likely lies on the line connecting the two closest points.
        Parameters:
        coord - reference
        geometry - to check against, explore all its coordinates
        Returns:
        closest coordinate distance
      • getClosestExistingCoordinateToPoint

        public org.locationtech.jts.geom.Coordinate getClosestExistingCoordinateToPoint​(org.locationtech.jts.geom.Coordinate coord,
                                                                                        org.locationtech.jts.geom.Geometry geometry)
        find the coordinate on the geometry with the closest distance to the reference point. Note that this is likely NOT the closest point to the geometry as this likely lies on the line connecting the two closest points.
        Parameters:
        coord - reference
        geometry - to check against, explore all its coordinates
        Returns:
        closest coordinate distance
      • getClosestExistingLineStringCoordinateToGeometry

        public <T extends org.locationtech.jts.geom.LineString> org.locationtech.jts.geom.Coordinate getClosestExistingLineStringCoordinateToGeometry​(org.locationtech.jts.geom.Geometry referenceGeometry,
                                                                                                                                                      T lineString)
        Find the coordinate on the line string with the closest distance to the reference referenceGeometry. Note that this is likely NOT the closest point to the geometry as this likely lies on the line connecting the two closest points.
        Type Parameters:
        T - type of line string
        Parameters:
        referenceGeometry - to use
        lineString - to verify closest coordinate
        Returns:
        closest existing coordinate on line string to find coordinate on
      • getClosestExistingLineStringCoordinateToGeometry

        public <T extends org.locationtech.jts.geom.LineString> org.locationtech.jts.geom.Coordinate getClosestExistingLineStringCoordinateToGeometry​(org.locationtech.jts.geom.Geometry referenceGeometry,
                                                                                                                                                      T lineString,
                                                                                                                                                      int startIndex,
                                                                                                                                                      int endIndex)
        Find the coordinate on the line string with the closest distance to the reference referenceGeometry. Note that this is likely NOT the closest point to the geometry as this likely lies on the line connecting the two closest points.
        Type Parameters:
        T - type of line string
        Parameters:
        referenceGeometry - to use
        lineString - to verify closest coordinate
        startIndex - start index offset to use (inclusive)
        endIndex - end index, i.e., last index to consider (inclusive)
        Returns:
        closest existing coordinate on line string to find coordinate on
      • getClosestProjectedLinearLocationOnGeometry

        public org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnGeometry​(org.locationtech.jts.geom.Coordinate reference,
                                                                                                         org.locationtech.jts.geom.Geometry geometry)
        find the closest location from the reference point to the geometry expressed as a linear location. Here we project onto the geometry, so we find the location with the actual closest distance and create a linear location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        reference - the reference location
        geometry - to find closest distance to point to
        Returns:
        linearLocation found
      • getClosestProjectedLinearLocationOnLineString

        public org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnLineString​(org.locationtech.jts.geom.Coordinate referenceCoordinate,
                                                                                                           org.locationtech.jts.geom.LineString lineString)
        Find the closest location from the reference coordinate to the line string expressed as a linear location. Here we project onto the geometry, so we find the location with the actual closest distance and create a linear location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        referenceCoordinate - the reference point
        lineString - to find closest distance to point to (must be a linear geometry)
        Returns:
        linearLocation found
      • getClosestProjectedLinearLocationOnPolygon

        public org.locationtech.jts.linearref.LinearLocation getClosestProjectedLinearLocationOnPolygon​(org.locationtech.jts.geom.Coordinate referenceCoordinate,
                                                                                                        org.locationtech.jts.geom.Polygon polygon)
        Find the closest location from the reference coordinate to the polygon expressed as a linear location. Here we project onto the geometry, so we find the location with the actual closest distance and create a linear location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        referenceCoordinate - the reference point
        polygon - to find closest distance to point to (must be a linear geometry)
        Returns:
        linearLocation found
      • getClosestGeometryExistingCoordinateToProjectedLinearLocationOnLineString

        public org.locationtech.jts.linearref.LinearLocation getClosestGeometryExistingCoordinateToProjectedLinearLocationOnLineString​(org.locationtech.jts.geom.Geometry referenceGeometry,
                                                                                                                                       org.locationtech.jts.geom.LineString linearGeometry)
        find the closest location from any existing coordinate of the reference geometry to the line string geometry as a linear location. Here we project onto the geometry, so we find the location with the actual closest distance and extract the linear location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        referenceGeometry - the reference geometry
        linearGeometry - to find closest distance to point to (must be a linear geometry)
        Returns:
        linearLocation found
      • getClosestProjectedCoordinateOnGeometry

        public org.locationtech.jts.geom.Coordinate getClosestProjectedCoordinateOnGeometry​(org.locationtech.jts.geom.Coordinate reference,
                                                                                            org.locationtech.jts.geom.Geometry geometry)
        find the closest projected coordinate from the reference point to the geometry. Here we project onto the geometry, so we find the location with the actual closest distance and create a coordinate at this location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        reference - the reference location
        geometry - to find closest distance to point to
        Returns:
        distance found in meters
      • getClosestProjectedCoordinateOnLineString

        public org.locationtech.jts.geom.Coordinate getClosestProjectedCoordinateOnLineString​(org.locationtech.jts.geom.Coordinate reference,
                                                                                              org.locationtech.jts.geom.LineString lineString)
        find the closest projected coordinate from the reference point to the line string. Here we project onto the geometry, so we find the location with the actual closest distance and create a coordinate at this location regardless if this coordinate is part of the geometry as a predefined coordinate at an extreme point.
        Parameters:
        reference - the reference point
        lineString - to find closest distance to point to
        Returns:
        distance found in meters
      • getClosestPojectedCoordinateOnPolygon

        public org.locationtech.jts.geom.Coordinate getClosestPojectedCoordinateOnPolygon​(org.locationtech.jts.geom.Coordinate reference,
                                                                                          org.locationtech.jts.geom.Polygon polygon)
        find the closest location from the reference coordinate to the polygon expressed as a linear location. Here we project onto the polygon, so we find the location with the actual closest distance and create a linear location regardless if this coordinate is part of the polygon as a predefined coordinate at an extreme point.
        Parameters:
        reference - the reference location
        polygon - to find closest distance to point to using its exterior ring
        Returns:
        linearLocation found
      • getClosestProjectedDistanceInMetersToLineString

        public double getClosestProjectedDistanceInMetersToLineString​(org.locationtech.jts.geom.Coordinate reference,
                                                                      org.locationtech.jts.geom.LineString geometry)
        find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
        Parameters:
        reference - the reference point
        geometry - to find closest distance to point to
        Returns:
        distance found in meters
      • getClosestDistanceInMetersMultiLineString

        public double getClosestDistanceInMetersMultiLineString​(org.locationtech.jts.geom.Coordinate reference,
                                                                org.locationtech.jts.geom.MultiLineString geometry)
        find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
        Parameters:
        reference - the reference location
        geometry - to find closest distance to point to
        Returns:
        distance found in meters
      • getClosestDistanceInMetersToPolygon

        public double getClosestDistanceInMetersToPolygon​(org.locationtech.jts.geom.Coordinate reference,
                                                          org.locationtech.jts.geom.Polygon geometry)
        find the closest distance in meters from the point to the geometry.Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
        Parameters:
        reference - the reference point
        geometry - to find closest distance to point to
        Returns:
        distance found in meters
      • getClosestDistanceInMeters

        public double getClosestDistanceInMeters​(org.locationtech.jts.geom.Coordinate reference,
                                                 org.locationtech.jts.geom.Geometry geometry)
        find the closest distance in meters from the point to the geometry. Here we project onto the geometry, so we find the actual closest distance instead of merely finding the closest modelled coordinated within the geometry.
        Parameters:
        reference - the reference location
        geometry - to find closest distance to point to
        Returns:
        distance found in meters
      • getDistanceInMetres

        public double getDistanceInMetres​(org.locationtech.jts.geom.Point startPosition,
                                          org.locationtech.jts.geom.Point endPosition)
        Compute the distance in metres between two (JTS) points assuming the positions are provided in the same crs as registered on this class instance
        Parameters:
        startPosition - location of the start point
        endPosition - location of the end point
        Returns:
        distance in metres between the points
      • getDistanceInMetres

        public double getDistanceInMetres​(org.locationtech.jts.geom.Coordinate startCoordinate,
                                          org.locationtech.jts.geom.Coordinate endCoordinate)
        Compute the distance in metres between two (JTS) coordinates assuming the positions are provided in the same crs as registered on this class instance
        Parameters:
        startCoordinate - location of the start point
        endCoordinate - location of the end point
        Returns:
        distance in metres between the points
      • isDistanceWithinMetres

        public boolean isDistanceWithinMetres​(org.locationtech.jts.geom.Coordinate startCoordinate,
                                              org.locationtech.jts.geom.Coordinate endCoordinate,
                                              double maxDistanceMeters)
        Determine if the distance in metres between two (JTS) coordinates (assuming the positions are provided in the same crs as registered on this class instance) is within the given distance
        Parameters:
        startCoordinate - location of the start point
        endCoordinate - location of the end point
        maxDistanceMeters - allowed
        Returns:
        true when distance in metres between the points is smaller, false otherwise
      • isDistanceWithinMetres

        public boolean isDistanceWithinMetres​(org.locationtech.jts.geom.Point startPosition,
                                              org.locationtech.jts.geom.Point endPosition,
                                              double maxDistanceMeters)
        Determine if the distance in metres between two (JTS) coordinates (assuming the positions are provided in the same crs as registered on this class instance) is within the given distance
        Parameters:
        startPosition - location of the start point
        endPosition - location of the end point
        maxDistanceMeters - allowed
        Returns:
        true when distance in metres between the points is smaller, false otherwise
      • getDistanceInKilometres

        public double getDistanceInKilometres​(org.locationtech.jts.geom.Point startPosition,
                                              org.locationtech.jts.geom.Point endPosition)
        Compute the distance in kilometres between two positions assuming the positions are provided in the same crs as registered on this class instance
        Parameters:
        startPosition - location of the start point
        endPosition - location of the end point
        Returns:
        distance in kilometres between the points
      • getDistanceInKilometres

        public double getDistanceInKilometres​(Vertex vertex1,
                                              Vertex vertex2)
        Compute the distance in kilometres between two vertices assuming the positions are set and based on the same crs as registered on this class instance
        Parameters:
        vertex1 - vertex with location
        vertex2 - vertex with location
        Returns:
        distance in kilometres between the points
      • createBoundingBox

        public org.locationtech.jts.geom.Envelope createBoundingBox​(double centrePointX,
                                                                    double centrePointY,
                                                                    double lengthMeters)
        create a square bounding box envelope instance based on the passed in reference point and length in meters of each of the legs, with the point residing in the middle, it is expected the locations (when no cartesian) are in LAT/LONG regardless of the transformation of the underlying CRS
        Parameters:
        centrePointX - x coord of centre in crs
        centrePointY - y coord of centre in crs
        lengthMeters - in meters
        Returns:
        envelope with appropriate square bounding box
      • createBoundingBox

        public org.locationtech.jts.geom.Envelope createBoundingBox​(org.locationtech.jts.geom.Envelope boundingBox,
                                                                    double lengthMeters)
        create a square bounding box envelope instance based on an existing envelope bounding box and and buffer length in meters resulting in a larger bounding box returned, it is expected the locations (when no cartesian) are in lat/long regardless of the transformation * of the underlying CRS
        Parameters:
        boundingBox - original bounding box
        lengthMeters - buffer length in meters
        Returns:
        envelope with appropriate square bounding box
      • createBoundingBox

        public org.locationtech.jts.geom.Envelope createBoundingBox​(double minX,
                                                                    double minY,
                                                                    double maxX,
                                                                    double maxY,
                                                                    double lengthMeters)
        create a square bounding box envelope instance based on the passed in bounding box coordinates and buffer length in meters resulting in a larger bounding box returned, it is expected the locations (when no cartesian) are in lat/long regardless of the transformation of the underlying CRS
        Parameters:
        minX - x (longitude) coord of minimum extreme point
        minY - y (latitude) coord of minimum extreme point
        maxX - x (longitude) coord of maximum extreme point
        maxY - y (latitude) coord of maximum extreme point
        lengthMeters - buffer length in meters
        Returns:
        envelope with appropriate square bounding box
      • getDistanceInKilometres

        public double getDistanceInKilometres​(org.locationtech.jts.geom.LineString geometry)
        Compute the length of the line string by traversing all nodes and computing the segment by segment distances TODO: find out if a faster way is possible
        Parameters:
        geometry - to extract length from
        Returns:
        length in km
      • createExtendedLineSegment

        public org.locationtech.jts.geom.LineSegment createExtendedLineSegment​(org.locationtech.jts.geom.LineSegment source,
                                                                               double extensionInMeters,
                                                                               boolean extendStart,
                                                                               boolean extendEnd)
        extend the given line segment in one or two directions with a given distance in meters. One can also extend on both sides at the same time. Note that this is not correcting for the curvature of the earth in case one uses a geodetic crs.
        Parameters:
        source - original line segment
        extensionInMeters - desired extension in meters
        extendStart - when true extend from start coordinate onwards
        extendEnd - when true extend further from end coordinate onwards
        Returns:
        extended line segment based on the passed in parameters
      • getCoordinateReferenceSystem

        public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
        collect the crs used by this instance of the utils class
        Returns:
        crs used by instance
      • getAzimuthInDegrees

        public double getAzimuthInDegrees​(org.locationtech.jts.geom.Coordinate coordinate1,
                                          org.locationtech.jts.geom.Coordinate coordinate2,
                                          boolean zeroTo360)
        Collect the azimuth heading between the two coordinates (lat/long) in decimal degrees
        Parameters:
        coordinate1 - first Coordinate
        coordinate2 - second Coordinate
        zeroTo360 - when true, return azimuth in zero to 360 degrees instead of 0-180,0-180 degrees
        Returns:
        azimuth in degrees
      • getAzimuthInDegrees

        public Double getAzimuthInDegrees​(org.opengis.geometry.coordinate.Position position1,
                                          org.opengis.geometry.coordinate.Position position2,
                                          boolean zeroTo360)
        Collect the azimuth heading between the two positions (in user CRS) in decimal degrees, from location 1 to location 2
        Parameters:
        position1 - first Coordinate
        position2 - second Coordinate
        zeroTo360 - when true, return azimuth in zero to 360 degrees instead of 0-180,0-180 degrees
        Returns:
        azimuth in degrees
      • toDirectPosition

        public org.opengis.geometry.DirectPosition toDirectPosition​(org.locationtech.jts.geom.Coordinate coordinate)
        extract direct position from coordinate
        Parameters:
        coordinate - to extract from
        Returns:
        coordinate + CRS as direct position
      • toDirectPosition

        public org.opengis.geometry.DirectPosition toDirectPosition​(org.locationtech.jts.geom.Point point)
        extract direct position from point
        Parameters:
        point - to extract from
        Returns:
        coordinate + CRS as direct position
      • isGeometryLeftOf

        public boolean isGeometryLeftOf​(org.locationtech.jts.geom.Geometry geometry,
                                        org.locationtech.jts.geom.Coordinate coordA,
                                        org.locationtech.jts.geom.Coordinate coordB)
        Verify if the provided geometry resides left of the line defined from coordA to coordB. If the geometry is not a point, we first find the closest location on the geometry to coordinate B and use that as a reference instead.
        Parameters:
        geometry - to check
        coordA - of line
        coordB - of line
        Returns:
        true when left, false otherwise
      • isGeometryNearBoundingBox

        public boolean isGeometryNearBoundingBox​(org.locationtech.jts.geom.Geometry geometry,
                                                 org.locationtech.jts.geom.Envelope boundingBox,
                                                 double maxDistanceMeters)
        Verify if any existing coordinate on the passed in geometry is within the maximum provided distance of the also provided bounding box
        Parameters:
        geometry - to check
        boundingBox - to consider
        maxDistanceMeters - to consider
        Returns:
        true when within maximum distance of bounding box, false otherwise