Package nz.org.riskscape.engine.geo
Class NearestNeighbourIndex
java.lang.Object
nz.org.riskscape.engine.geo.NearestNeighbourIndex
An index that when queried will return the nearest neighbour should one exist within a max distance.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionorg.locationtech.jts.geom.Envelopedoublefinal voidinsert(nz.org.riskscape.engine.Tuple item) Insert aTupleinto the index.static NearestNeighbourIndexmetricMaxDistance(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, double maxDistance) Create a nearest neighbour index with the given max distance (in metres).nz.org.riskscape.engine.Tuplequery(org.locationtech.jts.geom.Coordinate coordinate) Find the indexed entry that is closest to coordinate but still withinmaxDistanceInCrsUnits.
-
Method Details
-
metricMaxDistance
public static NearestNeighbourIndex metricMaxDistance(nz.org.riskscape.engine.types.Struct.StructMember geometryMember, nz.org.riskscape.engine.SRIDSet sridSet, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, double maxDistance) Create a nearest neighbour index with the given max distance (in metres).
- Parameters:
geometryMember- the geometry member that contains the geometry we are indexing from given tuplessridSet- an srid set to use for asserting that the geometry we end up indexing is in the correct CRS.crs- the coordinate reference system this index will be in. So far, this is not persisted with the index, but is used to derive a metric max distance and an expectedSridmaxDistance- the max distance (in metres ) that the match must be within. Note that if the CRS is not based on a metric grid, this will be an approximation.
-
insert
public final void insert(nz.org.riskscape.engine.Tuple item) Insert a
Tupleinto the index. The tuple will be indexed by to the geometry accessed withgeometryMemberAccessor.- Parameters:
item- to add to index
-
getEnvelope
public org.locationtech.jts.geom.Envelope getEnvelope()- Returns:
- the envelope that the index may provide matches within.
-
query
public nz.org.riskscape.engine.Tuple query(org.locationtech.jts.geom.Coordinate coordinate) Find the indexed entry that is closest to coordinate but still within
maxDistanceInCrsUnits.- Parameters:
coordinate- where to query the index- Returns:
- closest entry to coordinate, or null if there no entry is found with maxDistance.
-
getMaxDistanceInCrsUnits
public double getMaxDistanceInCrsUnits()
-