Class CRSUtils


  • public final class CRSUtils
    extends Object
    • Field Detail

      • DEFAULT_CRS

        public static final String DEFAULT_CRS
        Default is CRS:84 (EPSG:4326 with lon/lat ordering).
        See Also:
        Constant Field Values
      • crsFactory

        protected org.opengis.referencing.crs.CRSAuthorityFactory crsFactory
    • Method Detail

      • createPoint

        public org.locationtech.jts.geom.Point createPoint​(Double x,
                                                           Double y,
                                                           String srs)
        Creates a 2D point geometry within the given reference system.
        Parameters:
        x - the coordinate's x value.
        y - the coordinate's y value.
        srs - an authoritive spatial reference system code, e.g. EPSG:4326 or CRS:84 .
        Returns:
        a point referenced by the given spatial reference system.
      • createPoint

        public org.locationtech.jts.geom.Point createPoint​(Double x,
                                                           Double y,
                                                           Double z,
                                                           String srs)
        Creates a 2D point geometry with respect to its height and given reference system.
        Parameters:
        x - the point's x value.
        y - the point's y value.
        z - the height or null or NaN if coordinate is 2D.
        srs - an authoritive spatial reference system code, e.g. EPSG:4326 or CRS:84 .
        Returns:
        a point referenced by the given spatial reference system.
      • createLineString

        public org.locationtech.jts.geom.Geometry createLineString​(org.locationtech.jts.geom.Coordinate[] coordinates,
                                                                   String srs)
      • createGeometryFactory

        public org.locationtech.jts.geom.GeometryFactory createGeometryFactory()
      • createGeometryFactory

        public org.locationtech.jts.geom.GeometryFactory createGeometryFactory​(String srsId)
      • getSrsIdFrom

        public static int getSrsIdFrom​(String srs)
        Extracts the SRS number of the incoming SRS definition string. This can be either an HTTP URL (like http://www.opengis.net/def/crs/EPSG/0/4326) or a URN (like urn:ogc:def:crs:EPSG::31466).
        Parameters:
        srs - the SRS definition string, either as URL ('/'-separated) or as URN (': '-separated).
        Returns:
        the SRS number, e.g. 4326
      • extractSRSCode

        public static String extractSRSCode​(String srs)
        Parameters:
        srs - the SRS definition string, either as URL ('/'-separated) or as URN (': '-separated).
        Returns:
        SRS string in the form of for example 'EPSG:4326' or 'EPSG:31466'.
      • getSrsIdFromEPSG

        public static int getSrsIdFromEPSG​(String srs)
      • transformOuterToInner

        public org.locationtech.jts.geom.Point transformOuterToInner​(org.locationtech.jts.geom.Point point,
                                                                     String srcFrame)
                                                              throws org.opengis.referencing.FactoryException,
                                                                     org.opengis.referencing.operation.TransformException
        Transforms a given point from a given reference to inner reference, which is WGS84 (CRS:84).
        Parameters:
        point - the point to transform.
        srcFrame - the CRS authority code the given point is referenced in.
        Returns:
        a point referenced in WGS84
        Throws:
        org.opengis.referencing.FactoryException - if the creation of CoordinateReferenceSystem fails or no appropriate MathTransform could be created
        org.opengis.referencing.operation.TransformException - if transformation fails for any other reason
      • transformOuterToInner

        public org.locationtech.jts.geom.Geometry transformOuterToInner​(org.locationtech.jts.geom.Geometry geometry,
                                                                        String srcFrame)
                                                                 throws org.opengis.referencing.FactoryException,
                                                                        org.opengis.referencing.operation.TransformException
        Transforms a given geometry from a given reference to inner reference, which is WGS84 (CRS:84).
        Parameters:
        geometry - the geometry to transform.
        srcFrame - the CRS authority code the given point is referenced in.
        Returns:
        a geometry referenced in WGS84
        Throws:
        org.opengis.referencing.FactoryException - if the creation of CoordinateReferenceSystem fails or no appropriate MathTransform could be created.
        org.opengis.referencing.operation.TransformException - if transformation fails for any other reason.
      • transformInnerToOuter

        public org.locationtech.jts.geom.Geometry transformInnerToOuter​(org.locationtech.jts.geom.Geometry geometry,
                                                                        String destFrame)
                                                                 throws org.opengis.referencing.FactoryException,
                                                                        org.opengis.referencing.operation.TransformException
        Transforms a given geometry from its inner reference (which is WGS84 (CRS:84)) to a given reference.
        Parameters:
        geometry - the geometry to transform.
        destFrame - the CRS authority code the given point shall be transformed to.
        Returns:
        a transformed geometry with dest reference.
        Throws:
        org.opengis.referencing.FactoryException - if the creation of CoordinateReferenceSystem fails or no appropriate MathTransform could be created.
        org.opengis.referencing.operation.TransformException - if transformation fails for any other reason.
      • transform

        public org.locationtech.jts.geom.Geometry transform​(org.locationtech.jts.geom.Geometry geometry,
                                                            String srcFrame,
                                                            String destFrame)
                                                     throws org.opengis.referencing.FactoryException,
                                                            org.opengis.referencing.operation.TransformException
        Transforms a given geometry from a given reference to a destinated reference.
        Parameters:
        geometry - the geometry to transform.
        srcFrame - the reference the given point is in.
        destFrame - the reference frame the point shall be transformed to.
        Returns:
        a transformed point.
        Throws:
        org.opengis.referencing.FactoryException - if the creation of CoordinateReferenceSystem fails or no appropriate MathTransform could be created.
        org.opengis.referencing.operation.TransformException - if transformation fails for any other reason.
      • parseWkt

        public org.locationtech.jts.geom.Geometry parseWkt​(String wkt)
      • isLatLonAxesOrder

        public boolean isLatLonAxesOrder​(String outer)
                                  throws org.opengis.referencing.FactoryException
        Indicates if the given reference frame has switched axes compared to the inner default (lon/lat).
        Parameters:
        outer - the given reference frame code to check.
        Returns:
        true if axes order is switched compared to the inner default.
        Throws:
        org.opengis.referencing.FactoryException - if no proper CRS could be created.
      • isNorthingFirstEpsgCode

        public boolean isNorthingFirstEpsgCode​(int epsgCode)
                                        throws org.opengis.referencing.FactoryException
        Throws:
        org.opengis.referencing.FactoryException
      • isNorthingFirstEpsgCode

        public boolean isNorthingFirstEpsgCode​(String epsgCode)
                                        throws org.opengis.referencing.FactoryException
        Throws:
        org.opengis.referencing.FactoryException
      • createEpsgStrictAxisOrder

        public static CRSUtils createEpsgStrictAxisOrder()
        Creates an CRSUtils which offers assistance when doing spatial opererations. Strict means that all CRS defined with lat/lon axis ordering will be handled as defined.
        Returns:
        creates a reference helper which (strictly) handles referencing operations.
        Throws:
        IllegalStateException - if decoding default CRS fails.
      • createEpsgForcedXYAxisOrder

        public static CRSUtils createEpsgForcedXYAxisOrder()
        Creates a CRSUtils which offers assistance when doing spatial opererations. Forcing XY means that CRS axis ordering is considered lon/lat ordering, even if defined lat/lon.
        Returns:
        creates a reference helper which (strictly) handles referencing operations.
        Throws:
        IllegalStateException - if decoding default CRS fails.
      • createEpsgReferenceHelper

        public static CRSUtils createEpsgReferenceHelper​(org.geotools.util.factory.Hints hints)
                                                  throws IllegalStateException
        Creates a CRSUtils which offers assistance when doing spatial opererations.
        Parameters:
        hints - Some Geotools Hints which set behavior and special considerations regarding to the spatial operations.
        Returns:
        an instance of CRSUtils using given hints
        Throws:
        IllegalStateException