/** * Tests whether two geometries are exactly equal * in their normalized forms. * This is a convenience method which creates normalized * versions of both geometries before computing * {@link #equalsExact(Geometry)}. * <p> * This method is relatively expensive to compute. * For maximum performance, the client * should instead perform normalization on the individual geometries * at an appropriate point during processing. * * @param g a Geometry * @return true if the input geometries are exactly equal in their normalized form */ public boolean equalsNorm(Geometry g) { if (g == null) return false; return norm().equalsExact(g.norm()); }
/** * Tests whether two geometries are exactly equal * in their normalized forms. * This is a convenience method which creates normalized * versions of both geometries before computing * {@link #equalsExact(Geometry)}. * <p> * This method is relatively expensive to compute. * For maximum performance, the client * should instead perform normalization on the individual geometries * at an appropriate point during processing. * * @param g a Geometry * @return true if the input geometries are exactly equal in their normalized form */ public boolean equalsNorm(Geometry g) { if (g == null) return false; return norm().equalsExact(g.norm()); }
/** * Check Geometry type,X,Y,Z and SRID * * @param expectedWKT Expected value, in WKT * @param expectedSRID Expected SRID code, * @param valueObject Test value geometry ex rs.getObject(i) * @throws SQLException If WKT or WKB is not valid */ public static void assertGeometryEquals(String expectedWKT,int expectedSRID, Object valueObject) throws SQLException { if (expectedWKT == null) { assertNull(valueObject); } else { ValueGeometry expected = ValueGeometry.get(expectedWKT, expectedSRID); ValueGeometry actual = ValueGeometry.getFromGeometry(((Geometry)valueObject).norm()); expected = ValueGeometry.getFromGeometry(expected.getGeometry().norm()); String moreInfo = ""; if(!actual.equals(expected)) { if(!GeometryCollection.class.getName().equals(expected.getGeometry().getClass().getName()) && !GeometryCollection.class.getName().equals(actual.getGeometry().getClass().getName()) && expected.getGeometry().equals(actual.getGeometry())) { moreInfo = "\n But are topologically equals"; } } assertEquals("Expected:\n" + expected.getWKT() + "\nActual:\n" + actual.getWKT()+moreInfo, expected, actual); } } /**
/** * Check Geometry type,X,Y,Z and SRID * * @param expectedWKT Expected value, in WKT * @param expectedSRID Expected SRID code, * @param valueObject Test value geometry ex rs.getObject(i) * @throws SQLException If WKT or WKB is not valid */ public static void assertGeometryEquals(String expectedWKT,int expectedSRID, Object valueObject) throws SQLException { if (expectedWKT == null) { assertNull(valueObject); } else { ValueGeometry expected = ValueGeometry.get(expectedWKT, expectedSRID); ValueGeometry actual = ValueGeometry.getFromGeometry(((Geometry)valueObject).norm()); expected = ValueGeometry.getFromGeometry(expected.getGeometry().norm()); String moreInfo = ""; if(!actual.equals(expected)) { if(!GeometryCollection.class.getName().equals(expected.getGeometry().getClass().getName()) && !GeometryCollection.class.getName().equals(actual.getGeometry().getClass().getName()) && expected.getGeometry().equals(actual.getGeometry())) { moreInfo = "\n But are topologically equals"; } } assertEquals("Expected:\n" + expected.getWKT() + "\nActual:\n" + actual.getWKT()+moreInfo, expected, actual); } } /**
@Test public void testEnforcesPolygonNormalization() throws Exception { // outer ring in cw order, inner rings in ccw order String normalizedWKT = "POLYGON((0 0, 0 9, 9 9, 9 0, 0 0), (3 3, 6 3, 6 6, 3 6, 3 3))"; // outer ring in ccw order, inner rings in cc order String reversedWKT = "POLYGON((0 0, 9 0, 9 9, 0 9, 0 0), (3 3, 3 6, 6 6, 6 3, 3 3))"; Geometry normalized = new WKTReader().read(normalizedWKT); Geometry reversed = new WKTReader().read(reversedWKT); assertTrue(normalized.equalsExact(normalized.norm())); assertFalse(reversed.equalsExact(reversed.norm())); RevFeatureBuilder builder = builder(); RevFeature norm = builder.addValue(normalized).build(); RevFeature rev = builder.reset().addValue(reversed).build(); Geometry expected = (Geometry) norm.getValues().get(0).get(); Geometry actual = (Geometry) rev.getValues().get(0).get(); assertTrue(normalized.equalsExact(expected)); assertTrue(normalized.equalsExact(actual)); }