@Override public boolean intersects(final Geometry geometry) { if (envelopesIntersect(geometry)) { /** If any segments intersect, obviously intersects = true */ final List lineSegStr = SegmentStringUtil.extractSegmentStrings(geometry); // only request intersection finder if there are segments (ie NOT for // point // inputs) if (lineSegStr.size() > 0) { final boolean segsIntersect = getIntersectionFinder().intersects(lineSegStr); // MD - performance testing // boolean segsIntersect = false; if (segsIntersect) { return true; } } /** For L/L case we are done */ final int dimension = geometry.getDimension(); if (dimension == 1) { return false; } else if (dimension == 2 && Geometry.isAnyTargetComponentInTest(this, geometry)) { /** For L/A case, need to check for proper inclusion of the target in the test */ return true; } else if (dimension == 0) { /** For L/P case, need to check if any points lie on line(s) */ return isAnyTestPointInTarget(geometry); } else { return false; } } else { return false; } }
void run3() throws Exception { final String wkt = "MULTILINESTRING ((1335558.59524 631743.01449, 1335572.28215 631775.89056, 1335573.2578018496 631782.1915185435), (1335573.2578018496 631782.1915185435, 1335576.62035 631803.90754), (1335558.59524 631743.01449, 1335573.2578018496 631782.1915185435), (1335573.2578018496 631782.1915185435, 1335580.70187 631802.08139))"; final Geometry g = this.geometryFactory.geometry(wkt); final Geometry buf = g.buffer(15); // System.out.println(buf); };
void run2() throws Exception { final String wkt = "POLYGON ((-2531.310546875 -17.19328498840332, -2518.694580078125 -27.471830368041992, -2564.515869140625 -44.53504943847656, -2531.310546875 -17.19328498840332))"; final Geometry g = this.geometryFactory.geometry(wkt); final Geometry buf = g.buffer(1.0, 1); // System.out.println(buf); };
@Override public boolean test(final LineSegment line) { if (line == this.line) { return false; } else { final Geometry intersection = this.line.getIntersection(line); return intersection != null && !intersection.isEmpty(); } }
void run6() throws Exception { // polygon with two vertices very close - mitred negative buffer lies // outside input final String wkt = "POLYGON ((589081.1515112884 4518509.334764771, 589103.7370954598 4518497.015419995, 589099.8017397423 4518490.719003885, 589097.1198886324 4518486.20858194, 589090.9424687021 4518475.819013388, 589081.1515112884 4518509.334764771))"; final Geometry g = this.geometryFactory.geometry(wkt); final BufferParameters params = new BufferParameters(8, LineCap.ROUND, LineJoin.MITER, 5); final Geometry buf = g.buffer(-5, params); // System.out.println(buf); };
void run5() throws Exception { // polygon with two vertices very close - mitred negative buffer lies // outside input final String wkt = "POLYGON ((588722.7612465625 4518964.956739423, 588755.2073151038 4518948.2420851765, 588750.2892019567 4518938.490656119, 588750.2892047082 4518938.490654858, 588741.1098934844 4518920.290260831, 588722.7612465625 4518964.956739423))"; final Geometry g = this.geometryFactory.geometry(wkt); final BufferParameters params = new BufferParameters(8, LineCap.ROUND, LineJoin.MITER, 5); final Geometry buf = g.buffer(-5, params); // System.out.println(buf); };
public void testNormalizeMultiPoint() throws Exception { Geometry m = this.geometryFactory.geometry("MULTIPOINT((30 20),(10 10),(20 20),(30 30),(20 10))"); m = m.normalize(); final Punctual expectedValue = (Punctual) this.geometryFactory.geometry("MULTIPOINT((10 10),(20 10),(20 20),(30 20),(30 30))"); assertEqualsExact(expectedValue, m); final Punctual unexpectedValue = (Punctual) this.geometryFactory.geometry("MULTIPOINT((20 10),(20 20),(30 20),(30 30),(10 10))"); assertTrue(!m.equals(2, unexpectedValue)); }
/** * Tests whether any representative point of the test Geometry intersects the target geometry. * Only handles test geometries which are Punctual (dimension 0) * * @param geom a Punctual geometry to test * @return true if any point of the argument intersects the prepared geometry */ public boolean isAnyTestPointInTarget(final Geometry geometry) { /** * 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. */ final PointLocator locator = new PointLocator(); final Geometry realGeometry = getLine(); for (final Vertex vertex : geometry.vertices()) { if (realGeometry.intersects(vertex)) { return true; } } return false; }
public static Point[] getPointArray(final Geometry geometry, final int vertexCount) { final Point[] points = new Point[vertexCount]; int i = 0; for (final Vertex vertex : geometry.vertices()) { if (i > vertexCount) { break; } points[i++] = vertex.newPoint(); } return points; }
void run4() throws Exception { // String wkt = // "LINESTRING (1872699.676 530329.155, 1872712.232 530255.793, 1872724.601 // 530183.526, 1872737.157 530110.164, 1872749.713 530036.802, 1872762.082 // 529964.535, 1872774.638 529891.173, 1872787.194 529817.811, 1872799.563 // 529745.545, 1872812.119 529672.183, 1872824.675 529598.821, 1872837.044 // 529526.555, 1872849.6 529453.194, 1872862.156 529379.832, 1872874.524 // 529307.566, 1872887.08 529234.205, 1872899.636 529160.844, 1872912.005 // 529088.578, 1872924.561 529015.217, 1872937.117 528941.856, 1872949.486 // 528869.59, 1872962.042 528796.23)"; // String wkt = // "LINESTRING(1872762.082 529964.535, 1872774.638 529891.173, 1872787.194 // 529817.811)"; final String wkt = "LINESTRING (1872612.157 530840.503, 1872624.713 530767.14, 1872637.269 530693.777)"; final Geometry g = this.geometryFactory.geometry(wkt); final BufferParameters params = new BufferParameters(10, LineCap.SQUARE, LineJoin.MITER, 10); final Geometry buf = g.buffer(200, params); // System.out.println(buf); }
private void assertEqualsExact(final Geometry expectedValue, final Geometry actualValue) { assertTrue( "Expected " + expectedValue + " but encountered " + actualValue, actualValue.equals(2, expectedValue)); }
void doBuffer(final String wkt, final double dist, final int quadSegs) throws Exception { final Geometry g = this.geometryFactory.geometry(wkt); final Geometry buf = g.buffer(dist, quadSegs); // System.out.println(buf); };
public static Point[] getPointArray(final Geometry geometry) { return getPointArray(geometry, geometry.getVertexCount()); }