Class IntersectionIndex
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
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionIntersectionIndex
(StructMemberAccessExpression geometryMemberAccessor, nz.org.riskscape.engine.SRIDSet sridSet, IntersectionIndex.Options options) IntersectionIndex
(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet, IntersectionIndex.Options options) -
Method Summary
Modifier and TypeMethodDescriptionstatic IntersectionIndex.Options
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 tofindIntersections(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 differencesorg.geotools.geometry.jts.ReferencedEnvelope
void
insert
(nz.org.riskscape.engine.Tuple tuple) static IntersectionIndex
populateFromRelation
(nz.org.riskscape.engine.relation.Relation rhsRelation, nz.org.riskscape.engine.types.Type lhsGeomType, nz.org.riskscape.engine.SRIDSet sridSet, IntersectionIndex.Options options) Builds and populates anIntersectionIndex
with the content of aRelation
.static IntersectionIndex
withDefaultOptions
(StructMemberAccessExpression expression, nz.org.riskscape.engine.SRIDSet sridSet) static IntersectionIndex
withDefaultOptions
(nz.org.riskscape.engine.types.Struct.StructMember expression, nz.org.riskscape.engine.SRIDSet sridSet)
-
Constructor Details
-
IntersectionIndex
public IntersectionIndex(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet, IntersectionIndex.Options options) -
IntersectionIndex
public IntersectionIndex(StructMemberAccessExpression geometryMemberAccessor, nz.org.riskscape.engine.SRIDSet sridSet, IntersectionIndex.Options options)
-
-
Method Details
-
defaultOptions
-
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, IntersectionIndex.Options options) throws nz.org.riskscape.problem.ProblemException Builds and populates an
IntersectionIndex
with the content of aRelation
.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 fromlhsGeomType
- the type of the geometry member that will be used when querying the indexsridSet
-- Returns:
- index that is populated from rhsRelation
- Throws:
nz.org.riskscape.problem.ProblemException
- if rhsRelation has no geometry member
-
withDefaultOptions
public static IntersectionIndex withDefaultOptions(nz.org.riskscape.engine.types.Struct.StructMember expression, nz.org.riskscape.engine.SRIDSet sridSet) -
withDefaultOptions
public static IntersectionIndex withDefaultOptions(StructMemberAccessExpression expression, nz.org.riskscape.engine.SRIDSet sridSet) -
insert
public void insert(nz.org.riskscape.engine.Tuple tuple) -
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, findDifferenceAndIntersectionsnz.org.riskscape.engine.Tuple>>> (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
-