/** * Convenience method to test a point for intersection with * a Geometry * @param p the coordinate to test * @param geom the Geometry to test * @return <code>true</code> if the point is in the interior or boundary of the Geometry */ public boolean intersects(Coordinate p, Geometry geom) { return locate(p, geom) != Location.EXTERIOR; }
/** * @return true if the coord is located in the interior or boundary of * a geometry in the list. */ private boolean isCovered(Coordinate coord, List geomList) { for (Iterator it = geomList.iterator(); it.hasNext(); ) { Geometry geom = (Geometry) it.next(); int loc = ptLocator.locate(coord, geom); if (loc != Location.EXTERIOR) return true; } return false; }
public int getLocation(Coordinate pt) { if (isWithinToleranceOfBoundary(pt)) return Location.BOUNDARY; /* double dist = linework.distance(point); // if point is close to boundary, it is considered to be on the boundary if (dist < tolerance) return Location.BOUNDARY; */ // now we know point must be clearly inside or outside geometry, so return actual location value return ptLocator.locate(pt, g); }
private void computeContainmentDistance(GeometryLocation ptLoc, Polygon poly, GeometryLocation[] locPtPoly) { Coordinate pt = ptLoc.getCoordinate(); // if pt is not in exterior, distance to geom is 0 if (Location.EXTERIOR != ptLocator.locate(pt, poly)) { minDistance = 0.0; locPtPoly[0] = ptLoc; locPtPoly[1] = new GeometryLocation(poly, pt);; return; } }
private static Polygon findPolygonContaining(Geometry geom, Coordinate pt) { PointLocator locator = new PointLocator(); for (int i = 0; i < geom.getNumGeometries(); i++) { Polygon poly = (Polygon) geom.getGeometryN(i); int loc = locator.locate(pt, poly); if (loc == Location.INTERIOR) return poly; } return null; }
/** * Label an isolated node with its relationship to the target geometry. */ private void labelIsolatedNode(Node n, int targetIndex) { int loc = ptLocator.locate(n.getCoordinate(), arg[targetIndex].getGeometry()); n.getLabel().setAllLocations(targetIndex, loc); //debugPrintln(n.getLabel()); } }
/** * Determines the {@link Location} of the given {@link Coordinate} * in this geometry. * * @param pt the point to test * @return the location of the point in the geometry */ public int locate(Coordinate pt) { if (parentGeom instanceof Polygonal && parentGeom.getNumGeometries() > 50) { // lazily init point locator if (areaPtLocator == null) { areaPtLocator = new IndexedPointInAreaLocator(parentGeom); } return areaPtLocator.locate(pt); } return ptLocator.locate(pt, parentGeom); } }
/** * Label an isolated node with its relationship to the target geometry. */ private void labelIsolatedLine(Edge e, int targetIndex) { int loc = ptLocator.locate(e.getCoordinate(), op.getArgGeometry(targetIndex)); e.getLabel().setLocation(targetIndex, loc); }
/** * Label an isolated node with its relationship to the target geometry. */ private void labelIncompleteNode(Node n, int targetIndex) { int loc = ptLocator.locate(n.getCoordinate(), arg[targetIndex].getGeometry()); // MD - 2008-10-24 - experimental for now // int loc = arg[targetIndex].locate(n.getCoordinate()); n.getLabel().setLocation(targetIndex, loc); }
Point point = (Point) pointGeom.getGeometryN(i); Coordinate coord = point.getCoordinate(); int loc = locater.locate(coord, otherGeom); if (loc == Location.EXTERIOR) exteriorCoords.add(coord);
public void testPointLocator() throws Exception { PointLocator pointLocator = new PointLocator(); Geometry polygon = reader.read("POLYGON ((70 340, 430 50, 70 50, 70 340))"); assertEquals(Location.EXTERIOR, pointLocator.locate(new Coordinate(420, 340), polygon)); assertEquals(Location.BOUNDARY, pointLocator.locate(new Coordinate(350, 50), polygon)); assertEquals(Location.BOUNDARY, pointLocator.locate(new Coordinate(410, 50), polygon)); assertEquals(Location.INTERIOR, pointLocator.locate(new Coordinate(190, 150), polygon)); }
private void runPtLocator(int expected, Coordinate pt, String wkt) throws Exception { Geometry geom = reader.read(wkt); PointLocator pointLocator = new PointLocator(); int loc = pointLocator.locate(pt, geom); assertEquals(expected, loc); }
/** * Label an isolated edge of a graph with its relationship to the target geometry. * If the target has dim 2 or 1, the edge can either be in the interior or the exterior. * If the target has dim 0, the edge must be in the exterior */ private void labelIsolatedEdge(Edge e, int targetIndex, Geometry target) { // this won't work for GeometryCollections with both dim 2 and 1 geoms if ( target.getDimension() > 0) { // since edge is not in boundary, may not need the full generality of PointLocator? // Possibly should use ptInArea locator instead? We probably know here // that the edge does not touch the bdy of the target Geometry int loc = ptLocator.locate(e.getCoordinate(), target); e.getLabel().setAllLocations(targetIndex, loc); } else { e.getLabel().setAllLocations(targetIndex, Location.EXTERIOR); } //System.out.println(e.getLabel()); }
public void testPointLocatorLinearRingLineString() throws Exception { PointLocator pointLocator = new PointLocator(); Geometry gc = reader.read("GEOMETRYCOLLECTION( LINESTRING(0 0, 10 10), LINEARRING(10 10, 10 20, 20 10, 10 10))"); assertEquals(Location.BOUNDARY, pointLocator.locate(new Coordinate(10, 10), gc)); }