Class NearestNeighbourIndex

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

public class NearestNeighbourIndex extends Object

An index that when queried will return the nearest neighbour should one exist within a max distance.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.locationtech.jts.geom.Envelope
     
    double
     
    final void
    insert(nz.org.riskscape.engine.Tuple item)
    Insert a Tuple into the index.
    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).
    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.
    List<nz.org.riskscape.engine.coverage.SampledValue>
    queryKNearest(org.locationtech.jts.geom.Coordinate coordinate, int k)
    Find the k indexed entries closest to coordinate that are still within maxDistanceInCrsUnits.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 tuples
      sridSet - 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 expectedSrid
      maxDistance - 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 Tuple into the index. The tuple will be indexed by to the geometry accessed with geometryMemberAccessor.

      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.
    • queryKNearest

      public List<nz.org.riskscape.engine.coverage.SampledValue> queryKNearest(org.locationtech.jts.geom.Coordinate coordinate, int k)

      Find the k indexed entries closest to coordinate that are still within maxDistanceInCrsUnits.

      Parameters:
      coordinate - where to query the index
      k - the maximum number of results to return
      Returns:
      up to k entries sorted closest-first; may be fewer if fewer entries exist within maxDistance
    • getMaxDistanceInCrsUnits

      public double getMaxDistanceInCrsUnits()