Class IntersectionIndex

java.lang.Object
nz.org.riskscape.engine.geo.IntersectionIndex

public class IntersectionIndex extends Object

Creates an index of tuples using an underlying STRtree, implementing a couple of standard routines for querying the index for tuples, dealing with reprojection and other housekeeping concerns.

Note that testing is covered off for this by SpatialRelationTypedCoverage. (in defaults) but we could merge the tests and avoid retesting

  • Constructor Summary

    Constructors
    Constructor
    Description
    IntersectionIndex(StructMemberAccessExpression geometryMemberAccessor, nz.org.riskscape.engine.SRIDSet sridSet)
     
    IntersectionIndex(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    nz.org.riskscape.engine.util.Pair<Optional<org.locationtech.jts.geom.Geometry>,List<nz.org.riskscape.engine.util.Pair<org.locationtech.jts.geom.Geometry,nz.org.riskscape.engine.Tuple>>>
    findDifferenceAndIntersections(org.locationtech.jts.geom.Geometry geom)
    Similar to findIntersections(org.locationtech.jts.geom.Geometry) but also returns an optional geometry containing the difference.
    List<nz.org.riskscape.engine.util.Pair<org.locationtech.jts.geom.Geometry,nz.org.riskscape.engine.Tuple>>
    findIntersections(org.locationtech.jts.geom.Geometry geom)
    Query the index for any tuples that intersect the given geometry, returning the intersecting geometry and the tuple NB consider an option/alternative that doesn't return the intersecting geometry as it comes at a cost.
    List<nz.org.riskscape.engine.Tuple>
    findPointIntersections(org.locationtech.jts.geom.Point point)
    Query the index for any tuples that intersect with the given point, handling any required crs differences
    org.geotools.geometry.jts.ReferencedEnvelope
     
    void
    insert(nz.org.riskscape.engine.Tuple item)
     
    populateFromRelation(nz.org.riskscape.engine.relation.Relation rhsRelation, nz.org.riskscape.engine.types.Type lhsGeomType, nz.org.riskscape.engine.SRIDSet sridSet)
    Builds and populates an IntersectionIndex with the content of a Relation.

    Methods inherited from class java.lang.Object

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

    • IntersectionIndex

      public IntersectionIndex(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet)
    • IntersectionIndex

      public IntersectionIndex(StructMemberAccessExpression geometryMemberAccessor, nz.org.riskscape.engine.SRIDSet sridSet)
  • Method Details

    • populateFromRelation

      public static IntersectionIndex populateFromRelation(nz.org.riskscape.engine.relation.Relation rhsRelation, nz.org.riskscape.engine.types.Type lhsGeomType, nz.org.riskscape.engine.SRIDSet sridSet) throws nz.org.riskscape.problem.ProblemException

      Builds and populates an IntersectionIndex with the content of a Relation.

      If the CoordinateReferenceSystem of the rhsRelation and the lhsGeomType are different then the index will be populated with the geometry member re-projected to the lhsGeomType's projection if this is safe to do.

      In cases where there should be more lhs values than rhs then this should improve performance as there would be less re-projection overall.

      Re-projecting the rhs is only safe to do if we know that all of it's features will fit within the bounds of the lhs projection.

      Parameters:
      rhsRelation - relation to populate the index from
      lhsGeomType - the type of the geometry member that will be used when querying the index
      sridSet -
      Returns:
      index that is populated from rhsRelation
      Throws:
      nz.org.riskscape.problem.ProblemException - if rhsRelation has no geometry member
    • insert

      public void insert(nz.org.riskscape.engine.Tuple item)
    • getReferencedEnvelope

      public org.geotools.geometry.jts.ReferencedEnvelope getReferencedEnvelope()
    • findIntersections

      public List<nz.org.riskscape.engine.util.Pair<org.locationtech.jts.geom.Geometry,nz.org.riskscape.engine.Tuple>> findIntersections(org.locationtech.jts.geom.Geometry geom)

      Query the index for any tuples that intersect the given geometry, returning the intersecting geometry and the tuple NB consider an option/alternative that doesn't return the intersecting geometry as it comes at a cost.

      Discards any intersections that are not of an 'equivalent' geometry type as the product of intersecting the given geometry type and the indexed geometry type, according to GeometryFamily. These intersections are typically caused by glancing intersections where features share borders and vertices

      Parameters:
      geom - the geomerty to find the intersections on
      Returns:
      Tuple intersections the parameter geometry
    • findDifferenceAndIntersections

      public nz.org.riskscape.engine.util.Pair<Optional<org.locationtech.jts.geom.Geometry>,List<nz.org.riskscape.engine.util.Pair<org.locationtech.jts.geom.Geometry,nz.org.riskscape.engine.Tuple>>> findDifferenceAndIntersections(org.locationtech.jts.geom.Geometry geom)

      Similar to findIntersections(org.locationtech.jts.geom.Geometry) but also returns an optional geometry containing the difference. That is the area of geom that did not intersect with any features from the index. This will be empty if there is no difference.

      This method will calculate the difference in the CRS of the indexed geometries. This is to remove rounding errors that would occur if the difference was taken from geometries that had already been re-projected to another CRS.

      This method should only be used if the difference is required. Calculating the difference could be expensive, so if it is not needed use findIntersections(org.locationtech.jts.geom.Geometry).

      Parameters:
      geom - the geomerty to find the intersections on.
      Returns:
      Geometry, containing the area of geom that did not intersect, and intersections the parameter geometry.
    • findPointIntersections

      public List<nz.org.riskscape.engine.Tuple> findPointIntersections(org.locationtech.jts.geom.Point point)

      Query the index for any tuples that intersect with the given point, handling any required crs differences