locate method

int locate(
  1. Coordinate p,
  2. Geometry geom
)

Computes the topological relationship ({@link Location}) of a single point to a Geometry. It handles both single-element and multi-element Geometries. The algorithm for multi-part Geometries takes into account the SFS Boundary Determination Rule.

@return the {@link Location} of the point relative to the input Geometry

Implementation

int locate(Coordinate p, Geometry geom) {
  if (geom.isEmpty()) return Location.EXTERIOR;

  if (geom is LineString) {
    return locateOnLineString(p, geom);
  } else if (geom is Polygon) {
    return locateInPolygon(p, geom);
  }

  isIn = false;
  numBoundaries = 0;
  computeLocation(p, geom);
  if (boundaryRule.isInBoundary(numBoundaries)) return Location.BOUNDARY;
  if (numBoundaries > 0 || isIn) return Location.INTERIOR;

  return Location.EXTERIOR;
}