Package org.n52.io.crs
Class CRSUtils
- java.lang.Object
-
- org.n52.io.crs.CRSUtils
-
public final class CRSUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected org.opengis.referencing.crs.CRSAuthorityFactorycrsFactorystatic StringDEFAULT_CRSDefault is CRS:84 (EPSG:4326 with lon/lat ordering).static intEPSG_WGS84
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CRSUtilscreateEpsgForcedXYAxisOrder()Creates aCRSUtilswhich offers assistance when doing spatial opererations.static CRSUtilscreateEpsgReferenceHelper(org.geotools.util.factory.Hints hints)Creates aCRSUtilswhich offers assistance when doing spatial opererations.static CRSUtilscreateEpsgStrictAxisOrder()Creates anCRSUtilswhich offers assistance when doing spatial opererations.org.locationtech.jts.geom.GeometryFactorycreateGeometryFactory()org.locationtech.jts.geom.GeometryFactorycreateGeometryFactory(String srsId)org.locationtech.jts.geom.GeometrycreateLineString(org.locationtech.jts.geom.Coordinate[] coordinates, String srs)org.locationtech.jts.geom.PointcreatePoint(Double x, Double y, Double z, String srs)Creates a 2D point geometry with respect to its height and given reference system.org.locationtech.jts.geom.PointcreatePoint(Double x, Double y, String srs)Creates a 2D point geometry within the given reference system.static StringextractSRSCode(String srs)static intgetSrsIdFrom(String srs)Extracts the SRS number of the incoming SRS definition string.static intgetSrsIdFromEPSG(String srs)booleanisLatLonAxesOrder(String outer)Indicates if the given reference frame has switched axes compared to the inner default (lon/lat).booleanisNorthingFirstEpsgCode(int epsgCode)booleanisNorthingFirstEpsgCode(String epsgCode)org.locationtech.jts.geom.GeometryparseWkt(String wkt)org.locationtech.jts.geom.Geometrytransform(org.locationtech.jts.geom.Geometry geometry, String srcFrame, String destFrame)Transforms a given geometry from a given reference to a destinated reference.org.locationtech.jts.geom.GeometrytransformInnerToOuter(org.locationtech.jts.geom.Geometry geometry, String destFrame)Transforms a given geometry from its inner reference (which is WGS84 (CRS:84)) to a given reference.org.locationtech.jts.geom.GeometrytransformOuterToInner(org.locationtech.jts.geom.Geometry geometry, String srcFrame)Transforms a given geometry from a given reference to inner reference, which is WGS84 (CRS:84).org.locationtech.jts.geom.PointtransformOuterToInner(org.locationtech.jts.geom.Point point, String srcFrame)Transforms a given point from a given reference to inner reference, which is WGS84 (CRS:84).
-
-
-
Field Detail
-
EPSG_WGS84
public static final int EPSG_WGS84
- See Also:
- Constant Field Values
-
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:4326orCRS: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 ornullorNaNif coordinate is 2D.srs- an authoritive spatial reference system code, e.g.EPSG:4326orCRS: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 (likehttp://www.opengis.net/def/crs/EPSG/0/4326) or a URN (likeurn: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.TransformExceptionTransforms 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 ofCoordinateReferenceSystemfails or no appropriateMathTransformcould be createdorg.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.TransformExceptionTransforms 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 ofCoordinateReferenceSystemfails or no appropriateMathTransformcould 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.TransformExceptionTransforms 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 ofCoordinateReferenceSystemfails or no appropriateMathTransformcould 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.TransformExceptionTransforms 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 ofCoordinateReferenceSystemfails or no appropriateMathTransformcould 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:
trueif 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 anCRSUtilswhich 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 aCRSUtilswhich 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 aCRSUtilswhich offers assistance when doing spatial opererations.- Parameters:
hints- Some GeotoolsHintswhich set behavior and special considerations regarding to the spatial operations.- Returns:
- an instance of
CRSUtilsusing given hints - Throws:
IllegalStateException
-
-