/** * 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; }
/** * 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; }
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; }
public Geometry union() PointLocator locater = new PointLocator();
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 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)); }
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)); }