Class SRIDSet
SRIDSet is the "central authority" in riskscape for managing CoordinateReferenceSystems. It's responsible for:
- maintaining a map of
CoordinateReferenceSystem
s to opaquesrid
integers, dealing with what constitutes an 'equals' CRS for the purposes of RiskScape - Caching a set of maths transformations used for reprojecting geometry between known crs objects, plus a convenience method for consistently reprojecting geometry
- Getting GeometryFactory objects that will return Geometry with the correct SRID so that this SRIDSet can correctly link it to a CoordinateReferenceSystem
TODO the API on this is horrible - it isn't clear about the side effects - rename methods please to make side effects
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.geotools.api.referencing.crs.CoordinateReferenceSystem
CRS for use on mainland New Zealandstatic final org.geotools.api.referencing.crs.CoordinateReferenceSystem
World coordinate system in lat/lon (y/x).static final org.geotools.api.referencing.crs.CoordinateReferenceSystem
World coordinate system in lon/lat (x/y).static final int
Geometry's with this srid have not had an srid assigned by an SridSet.static final org.geotools.api.referencing.crs.CoordinateReferenceSystem
A 2D wild card CRS. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all cached state from this SRIDSet See https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/389 for some backgroundstatic org.geotools.api.referencing.crs.CoordinateReferenceSystem
static org.geotools.api.referencing.crs.CoordinateReferenceSystem
epsgToCrsWithForceXY
(String epsgCode) Similar toepsgToCrs(java.lang.String)
except that aCoordinateReferenceSystem
with an XY axis order will be returned regardless of how the CRS is defined.org.geotools.api.referencing.crs.CoordinateReferenceSystem
get
(int id) int
get
(@NonNull org.geotools.api.data.FeatureSource<?, ?> fs) int
get
(@NonNull org.geotools.api.feature.type.FeatureType type) int
get
(@NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) org.geotools.api.referencing.crs.CoordinateReferenceSystem
get
(@NonNull org.locationtech.jts.geom.Geometry geometry) org.locationtech.jts.geom.GeometryFactory
getGeometryFactory
(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) org.geotools.api.referencing.operation.MathTransform
getReprojectionTransform
(int sourceSrid, int targetSrid) Get aMathTransform
that can be used to re-project from sourceCrs to targetCrs.Controls if geometries should be validated after a re-projection and what to do if they have become invalid.org.geotools.api.data.Query
queryWithHints
(org.geotools.api.data.Query query, @NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) void
remember
(@NonNull org.geotools.api.data.SimpleFeatureSource fs) org.locationtech.jts.geom.Geometry
reproject
(org.locationtech.jts.geom.Geometry geom, int targetSrid) Reprojects geom to be in the targetSrid.org.locationtech.jts.geom.Geometry
reproject
(org.locationtech.jts.geom.Geometry geom, org.geotools.api.referencing.operation.MathTransform transform, org.geotools.api.referencing.crs.CoordinateReferenceSystem sourceCrs, org.geotools.api.referencing.crs.CoordinateReferenceSystem targetCrs) Reprojects geom using the suppliedMathTransform
and applies standard rules for the fixing and logging of geometry that may become invalid during the reprojection.boolean
requiresReprojection
(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs1, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs2) Test ifGeometry
s in the inputCoordinateReferenceSystem
s would need to be reprojected before geometry operations could be performed accurately.void
setValidationPostReproject
(GeometryValidation validationPostReproject) Controls if geometries should be validated after a re-projection and what to do if they have become invalid.
-
Field Details
-
UNSET_SRID
public static final int UNSET_SRIDGeometry's with this srid have not had an srid assigned by an SridSet.
- See Also:
-
EPSG4326_LONLAT
public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem EPSG4326_LONLATWorld coordinate system in lon/lat (x/y).
-
EPSG4326_LATLON
public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem EPSG4326_LATLONWorld coordinate system in lat/lon (y/x). Caution should be taken with this CRS because it has previously been defined as lon/lat and many other software packages still treat it that way.
-
EPSG2193_NZTM
public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem EPSG2193_NZTMCRS for use on mainland New Zealand
-
WILDCARD_2D
public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem WILDCARD_2DA 2D wild card CRS.
-
crsById
-
sridByCrs
-
sridByMetadataFreeCrs
-
cachedTransforms
-
cachedGeometryFactories
-
-
Constructor Details
-
SRIDSet
public SRIDSet() -
SRIDSet
-
-
Method Details
-
epsgToCrs
- Parameters:
epsgCode
- code to get the CRS for- Returns:
- CRS
- Throws:
RiskscapeException
- if epsgCode does not identify a known CRS
-
epsgToCrsWithForceXY
public static org.geotools.api.referencing.crs.CoordinateReferenceSystem epsgToCrsWithForceXY(String epsgCode) Similar to
epsgToCrs(java.lang.String)
except that aCoordinateReferenceSystem
with an XY axis order will be returned regardless of how the CRS is defined.- Parameters:
epsgCode
- code to get the CRS for- Returns:
- CRS
- Throws:
RiskscapeException
- if epsgCode does not identify a known CRS
-
get
public org.geotools.api.referencing.crs.CoordinateReferenceSystem get(int id) -
get
public int get(@NonNull @NonNull org.geotools.api.data.FeatureSource<?, ?> fs) -
get
public int get(@NonNull @NonNull org.geotools.api.feature.type.FeatureType type) -
get
public int get(@NonNull @NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) -
clear
public void clear()Clear all cached state from this SRIDSet See https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/389 for some background
-
get
public org.geotools.api.referencing.crs.CoordinateReferenceSystem get(@NonNull @NonNull org.locationtech.jts.geom.Geometry geometry) -
remember
public void remember(@NonNull @NonNull org.geotools.api.data.SimpleFeatureSource fs) -
queryWithHints
public org.geotools.api.data.Query queryWithHints(@NonNull org.geotools.api.data.Query query, @NonNull @NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) -
getReprojectionTransform
public org.geotools.api.referencing.operation.MathTransform getReprojectionTransform(int sourceSrid, int targetSrid) Get a
MathTransform
that can be used to re-project from sourceCrs to targetCrs.Getting the
MathTransform
may be preferable to callingreproject(Geometry, int)
where the calling code also needs to do an inverse transform.If a datum shift aware transformation cannot be obtained, then a transform that ignores datum shifts will be returned. In this case a warning will be output, but note that the warning will be output once, not every time that that transformation is used.
- Parameters:
sourceSrid
- the source SRIDtargetSrid
- the target SRID- Returns:
- a math transform
-
reproject
public org.locationtech.jts.geom.Geometry reproject(org.locationtech.jts.geom.Geometry geom, int targetSrid) throws GeometryReprojectionException Reprojects geom to be in the targetSrid.
- Parameters:
geom
-targetSrid
- that desired srid- Returns:
- geom in targetSrid or the input geom if already in targetSrid
- Throws:
GeometryReprojectionException
- if the reprojection is not possible. Normally because the geom does not wholly fit into the new CRSGeometryInvalidException
- if the reprojected geometry is not valid (and geometry validation is set to error)
-
reproject
public org.locationtech.jts.geom.Geometry reproject(org.locationtech.jts.geom.Geometry geom, org.geotools.api.referencing.operation.MathTransform transform, org.geotools.api.referencing.crs.CoordinateReferenceSystem sourceCrs, org.geotools.api.referencing.crs.CoordinateReferenceSystem targetCrs) throws org.geotools.api.referencing.operation.TransformException Reprojects geom using the supplied
MathTransform
and applies standard rules for the fixing and logging of geometry that may become invalid during the reprojection.Note that this method is only intended for use in special cases that would also use
getReprojectionTransform(int, int)
.- Parameters:
geom
- geometry to be reprojectedtransform
- math transform used to do the reprojectionsourceCrs
- the CRS that geom is in. Used for problem loggingtargetCrs
- the CRS that geom is reprojected to. Used for problem logging- Returns:
- the reprojected geometry
- Throws:
org.geotools.api.referencing.operation.TransformException
- should the transformation not be possible.
-
requiresReprojection
public boolean requiresReprojection(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs1, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs2) Test if
Geometry
s in the inputCoordinateReferenceSystem
s would need to be reprojected before geometry operations could be performed accurately.- Returns:
- true if
Geometry
in these CRSs would need to reprojected before doing geometry operations
-
getGeometryFactory
public org.locationtech.jts.geom.GeometryFactory getGeometryFactory(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs) - Returns:
- a
GeometryFactory
that returnsGeometry
objects that are assigned an srid that is mapped to the givenCoordinateReferenceSystem
.
-
getValidationPostReproject
Controls if geometries should be validated after a re-projection and what to do if they have become invalid.
-
setValidationPostReproject
Controls if geometries should be validated after a re-projection and what to do if they have become invalid.
-