Class SRIDSet

java.lang.Object
nz.org.riskscape.engine.SRIDSet

public class SRIDSet extends Object

SRIDSet is the "central authority" in riskscape for managing CoordinateReferenceSystems. It's responsible for:

  • maintaining a map of CoordinateReferenceSystems to opaque srid 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

    Fields
    Modifier and Type
    Field
    Description
    protected final Map<Integer,org.locationtech.jts.geom.GeometryFactory>
     
    protected final Map<List<Integer>,org.geotools.api.referencing.operation.MathTransform>
     
    protected final Map<Integer,org.geotools.api.referencing.crs.CoordinateReferenceSystem>
     
    static final org.geotools.api.referencing.crs.CoordinateReferenceSystem
    CRS for use on mainland New Zealand
    static 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).
    protected final Map<org.geotools.api.referencing.crs.CoordinateReferenceSystem,Integer>
     
    protected final Map<nz.org.riskscape.engine.SRIDSet.MetaDataFreeCRS,Integer>
     
    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

    Constructors
    Constructor
    Description
     
    SRIDSet(ProblemSink problemSink)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear all cached state from this SRIDSet See https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/389 for some background
    static org.geotools.api.referencing.crs.CoordinateReferenceSystem
    epsgToCrs(String epsgCode)
     
    static org.geotools.api.referencing.crs.CoordinateReferenceSystem
    Similar to epsgToCrs(java.lang.String) except that a CoordinateReferenceSystem 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 a MathTransform 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 supplied MathTransform 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 if Geometrys in the input CoordinateReferenceSystems would need to be reprojected before geometry operations could be performed accurately.
    void
    Controls if geometries should be validated after a re-projection and what to do if they have become invalid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNSET_SRID

      public static final int UNSET_SRID

      Geometry'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_LONLAT

      World coordinate system in lon/lat (x/y).

    • EPSG4326_LATLON

      public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem EPSG4326_LATLON

      World 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_NZTM

      CRS for use on mainland New Zealand

    • WILDCARD_2D

      public static final org.geotools.api.referencing.crs.CoordinateReferenceSystem WILDCARD_2D

      A 2D wild card CRS.

    • crsById

      protected final Map<Integer,org.geotools.api.referencing.crs.CoordinateReferenceSystem> crsById
    • sridByCrs

      protected final Map<org.geotools.api.referencing.crs.CoordinateReferenceSystem,Integer> sridByCrs
    • sridByMetadataFreeCrs

      protected final Map<nz.org.riskscape.engine.SRIDSet.MetaDataFreeCRS,Integer> sridByMetadataFreeCrs
    • cachedTransforms

      protected final Map<List<Integer>,org.geotools.api.referencing.operation.MathTransform> cachedTransforms
    • cachedGeometryFactories

      protected final Map<Integer,org.locationtech.jts.geom.GeometryFactory> cachedGeometryFactories
  • Constructor Details

    • SRIDSet

      public SRIDSet()
    • SRIDSet

      public SRIDSet(ProblemSink problemSink)
  • Method Details

    • epsgToCrs

      public static org.geotools.api.referencing.crs.CoordinateReferenceSystem epsgToCrs(String epsgCode)
      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 a CoordinateReferenceSystem 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 calling reproject(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 SRID
      targetSrid - 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 CRS
      GeometryInvalidException - 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 reprojected
      transform - math transform used to do the reprojection
      sourceCrs - the CRS that geom is in. Used for problem logging
      targetCrs - 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 Geometrys in the input CoordinateReferenceSystems 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 returns Geometry objects that are assigned an srid that is mapped to the given CoordinateReferenceSystem.
    • getValidationPostReproject

      public GeometryValidation getValidationPostReproject()

      Controls if geometries should be validated after a re-projection and what to do if they have become invalid.

    • setValidationPostReproject

      public void setValidationPostReproject(GeometryValidation validationPostReproject)

      Controls if geometries should be validated after a re-projection and what to do if they have become invalid.