void assertEqualsExact(Geometry g1, Geometry g2, String msg) { Geometry g1Clone = (Geometry) g1.clone(); Geometry g2Clone = (Geometry) g2.clone(); g1Clone.normalize(); g2Clone.normalize(); assertTrue(g1Clone.equalsExact(g2Clone), msg); }
private boolean alreadyThere(Geometry g) { Iterator it = lines.iterator(); while (it.hasNext()) { Geometry lineg = (Geometry) it.next(); if (lineg.equalsExact(g)) return true; else if (equalsExactBackwards(lineg, g)) return true; } return false; }
void checkTransformation(String geomStr) throws IOException, ParseException, NoninvertibleTransformationException { Geometry geom = rdr.read(geomStr); AffineTransformation trans = AffineTransformation.rotationInstance(Math.PI / 2); AffineTransformation inv = trans.getInverse(); Geometry transGeom = (Geometry) geom.clone(); transGeom.apply(trans); // System.out.println(transGeom); transGeom.apply(inv); // check if transformed geometry is equal to original boolean isEqual = geom.equalsExact(transGeom, 0.0005); assertTrue(isEqual); }
@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()); }
@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()); }
/** * Returns 0 if the features are the same. 1 if the attributes are the same but have different * featureIDs and -1 if attributes are different or are of different featureTypes. * * @param feature1 * @param feature2 * @return */ public static int same(SimpleFeature feature1, SimpleFeature feature2) { if (DataUtilities.compare(feature1.getFeatureType(), feature2.getFeatureType()) != 0) { return -1; } for (int i = 0; i < feature1.getAttributeCount(); i++) { if (feature1.getAttribute(i) == null) { if (feature2.getAttribute(i) != null) return -1; else continue; } if (feature1.getAttribute(i) instanceof Geometry) { Geometry geom1 = (Geometry) feature1.getAttribute(i); if (feature2.getAttribute(i) instanceof Geometry) { Geometry geom2 = (Geometry) feature2.getAttribute(i); if (geom1.equalsExact(geom2)) continue; else return -1; } else return -1; } if (!feature1.getAttribute(i).equals(feature2.getAttribute(i))) return -1; } return feature1.getID().equals(feature2.getID()) ? 0 : 1; }