public static boolean equalsExact(Geometry arg0, Geometry arg1) { if (arg0 == null || arg1 == null) return false; Geometry _this = arg0; return _this.equalsExact(arg1); }
public static boolean equalsExactTolerance(Geometry arg0, Geometry arg1, Double arg2) { if (arg0 == null || arg1 == null || arg2 == null) return false; Geometry _this = arg0; return _this.equalsExact(arg1, arg2); }
@Test public void testLeaveNative() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart()); assertEquals("EPSG:3004", fti.getSRS()); assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that the geometry was left in tact Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)"))); fi.close(); assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testReproject() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart()); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was actually reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse( g.equalsExact( WKT.read( "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testWithRename() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName("MyPoints"); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse(g.equalsExact(WKT.read("POINT(500050 500050)"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
/** Compares two geometries for equality. */ protected void assertEquals(Geometry expected, Geometry actual) { if (expected == actual) { return; } assertNotNull(expected); assertNotNull(actual); assertTrue(expected.equalsExact(actual)); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(primitive, fs.getSchema()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(primitive, fc.getSchema()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); // check mappings occurred assertEquals("description-f001", sf.getAttribute("description")); assertTrue( new WKTReader() .read("MULTIPOINT(39.73245 2.00342)") .equalsExact((Geometry) sf.getAttribute("pointProperty"))); assertEquals(Long.valueOf(155), sf.getAttribute("intProperty")); assertNull(sf.getAttribute("newProperty")); }
/** Compares two geometries for equality. */ protected void assertEquals(String message, Geometry expected, Geometry actual) { if (expected == actual) { return; } assertNotNull(message, expected); assertNotNull(message, actual); assertTrue(message, expected.equalsExact(actual)); }
@Override public boolean evaluateInternal(Geometry left, Geometry right) { Envelope envLeft = left.getEnvelopeInternal(); Envelope envRight = right.getEnvelopeInternal(); if (envRight.equals(envLeft)) return left.equalsExact(right); else return false; }
@DescribeProcess( title = "Exactly Equal Test", description = "Tests if two geometries are identical on a vertex-by-vertex basis." ) @DescribeResult(description = "True if the geometries are vertex-identical") public static boolean equalsExact( @DescribeParameter(name = "a", description = "First input geometry") Geometry a, @DescribeParameter(name = "b", description = "Second input geometry") Geometry b) { return a.equalsExact(b); }
@Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); // is it a rectangle? if (geom != null && geom.equalsExact(geom.getEnvelope())) { GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal()); Geometry intersect = clipper.clip(getAsGeometry(), true); return new ROIGeometry(intersect); } else { return super.intersect(roi); } }
@Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); // is it a rectangle? if (geom != null && geom.equalsExact(geom.getEnvelope())) { GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal()); Geometry intersect = clipper.clip(getAsGeometry(), true); return new ROIGeometry(intersect, hints); } else { return super.intersect(roi); } }
boolean hasSameValuesAndStructure(Geometry g1, Geometry g2) { if (!g1.equalsExact(g2, ORD_TOLERANCE)) return false; if (g1.getFactory() != g2.getFactory()) return false; CoordinateSequence seq = CoordinateSequenceFinder.find(g1); if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(), seq.getDimension())) return false; return true; }
@Test public void testDonutCrossingInvalid() throws Exception { Geometry g = wkt.read("POLYGON((6 2, 14 2, 14 8, 6 8, 6 2), (8 4, 12 4, 12 6, 8 6, 8 4))"); Geometry clipped = clipper.clip(g, false); // System.out.println(clipped); assertTrue( clipped.equalsExact( wkt.read( "POLYGON ((10 2, 10 8, 6 8, 6 2, 10 2), (10 4, 10 6, 8 6, 8 4, 10 4))"))); showResult("Donut crossing, invalid geom", g, clipped); }
@Test public void testInsidePolygon() throws Exception { Geometry g = wkt.read("POINT(5 5)").buffer(2); Geometry clipped = clipper.clip(g, false); assertTrue(g.equalsExact(clipped)); showResult("Polygon inside", g, clipped); }
@Test public void testDonutHoleOutside() throws Exception { Geometry g = wkt.read("POLYGON((6 2, 14 2, 14 8, 6 8, 6 2), (11 4, 12 4, 12 6, 11 6, 11 4))"); Geometry clipped = clipper.clip(g, false); // System.out.println(clipped); assertTrue(clipped.equalsExact(wkt.read("POLYGON ((10 2, 10 8, 6 8, 6 2, 10 2))"))); showResult("Donut crossing, invalid geom", g, clipped); }
@Test public void testDonutCrossingValid() throws Exception { Geometry g = wkt.read("POLYGON((6 2, 14 2, 14 8, 6 8, 6 2), (8 4, 12 4, 12 6, 8 6, 8 4))"); Geometry clipped = clipper.clip(g, true); assertTrue( clipped.equalsExact( wkt.read("POLYGON ((10 2, 6 2, 6 8, 10 8, 10 6, 8 6, 8 4, 10 4, 10 2))"))); showResult("Donut crossing, valid geom", g, clipped); }
@Test public void testTouchAndCross() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 5 2, 5 3, -5 3, 0 4)"); Geometry clipped = clipper.clip(ls, false); assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 5 2, 5 3, 0 3)"))); showResult("Touch and cross", ls, clipped); }
@Test public void testTouchAndParallel() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 0 2, 0 3, -5 3, 0 4)"); Geometry clipped = clipper.clip(ls, false); assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 0 3)"))); showResult("Touch and parallel", ls, clipped); }
@Test public void testPolygonCrossingThreeSides() throws Exception { Geometry g = wkt.read("POLYGON((-2 2, 12 2, 12 12, -2 12, -2 2))"); Geometry clipped = clipper.clip(g, false); assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 10 2, 10 10, 0 10, 0 2))"))); showResult("Crossing three sides", g, clipped); }