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; }
private void computeLocation(Coordinate p, Geometry geom) updateLocationInfo(locateOnPoint(p, (Point) geom)); updateLocationInfo(locateOnLineString(p, (LineString) geom)); updateLocationInfo(locateInPolygon(p, (Polygon) geom)); for (int i = 0; i < ml.getNumGeometries(); i++) { LineString l = (LineString) ml.getGeometryN(i); updateLocationInfo(locateOnLineString(p, l)); for (int i = 0; i < mpoly.getNumGeometries(); i++) { Polygon poly = (Polygon) mpoly.getGeometryN(i); updateLocationInfo(locateInPolygon(p, poly)); Geometry g2 = (Geometry) geomi.next(); if (g2 != geom) computeLocation(p, g2);
/** * Tests whether any representative of the target geometry * intersects the test geometry. * This is useful in A/A, A/L, A/P, L/P, and P/P cases. * * @param testGeom the test geometry * @return true if any component intersects the areal test geometry */ public boolean isAnyTargetComponentInTest(Geometry testGeom) { PointLocator locator = new PointLocator(); for (Iterator i = representativePts.iterator(); i.hasNext(); ) { Coordinate p = (Coordinate) i.next(); if (locator.intersects(p, testGeom)) return true; } return false; }
/** * 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; }
/** * 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 */ public int locate(Coordinate p, Geometry geom) { if (geom.isEmpty()) return Location.EXTERIOR; if (geom instanceof LineString) { return locateOnLineString(p, (LineString) geom); } else if (geom instanceof Polygon) { return locateInPolygon(p, (Polygon) 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; }
private int locateInPolygon(Coordinate p, Polygon poly) { if (poly.isEmpty()) return Location.EXTERIOR; LinearRing shell = poly.getExteriorRing(); int shellLoc = locateInPolygonRing(p, shell); if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR; if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = poly.getInteriorRingN(i); int holeLoc = locateInPolygonRing(p, hole); if (holeLoc == Location.INTERIOR) return Location.EXTERIOR; if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY; } return Location.INTERIOR; }
/** * @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; }
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); }
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); }
/** * Tests whether any representative point of the test Geometry intersects * the target geometry. * Only handles test geometries which are Puntal (dimension 0) * * @param geom a Puntal geometry to test * @return true if any point of the argument intersects the prepared geometry */ protected boolean isAnyTestPointInTarget(Geometry testGeom) { /** * This could be optimized by using the segment index on the lineal target. * However, it seems like the L/P case would be pretty rare in practice. */ PointLocator locator = new PointLocator(); List coords = ComponentCoordinateExtracter.getCoordinates(testGeom); for (Iterator i = coords.iterator(); i.hasNext(); ) { Coordinate p = (Coordinate) i.next(); if (locator.intersects(p, prepLine.getGeometry())) return true; } return false; }
public Geometry union() PointLocator locater = new PointLocator(); Point point = (Point) pointGeom.getGeometryN(i); Coordinate coord = point.getCoordinate(); int loc = locater.locate(coord, otherGeom); if (loc == Location.EXTERIOR) exteriorCoords.add(coord);
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; } }
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)); }
/** * 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); } }
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)); }
/** * 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()); } }
/** * 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); }
/** * 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()); }