org.locationtech.jts.geom.Geometry.equalsExact()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(356)

本文整理了Java中org.locationtech.jts.geom.Geometry.equalsExact()方法的一些代码示例,展示了Geometry.equalsExact()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.equalsExact()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:equalsExact

Geometry.equalsExact介绍

[英]Returns true if the two Geometrys are exactly equal. Two Geometries are exactly equal iff:

  • they have the same structure
  • they have the same values for their vertices, in exactly the same order.
    This provides a stricter test of equality than #equalsTopo(Geometry), which is more useful in certain situations (such as using geometries as keys in collections).

This method does not test the values of the GeometryFactory, the SRID, or the userData fields.

To properly test equality between different geometries, it is usually necessary to #normalize() them first.
[中]如果两个Geometry完全相等,则返回true。两个几何体完全相等:
*它们具有相同的结构
*它们的顶点具有相同的值,顺序完全相同。
这提供了比#equalsTopo(几何体)更严格的相等性测试,它在某些情况下更有用(例如将几何体用作集合中的键)。
此方法不测试GeometryFactorySRIDuserData字段的值。
为了正确测试不同几何体之间的相等性,通常需要首先对它们进行#规格化()。

代码示例

代码示例来源:origin: geotools/geotools

  1. public static boolean equalsExact(Geometry arg0, Geometry arg1) {
  2. if (arg0 == null || arg1 == null) return false;
  3. Geometry _this = arg0;
  4. return _this.equalsExact(arg1);
  5. }

代码示例来源:origin: geotools/geotools

  1. public static boolean equalsExactTolerance(Geometry arg0, Geometry arg1, Double arg2) {
  2. if (arg0 == null || arg1 == null || arg2 == null) return false;
  3. Geometry _this = arg0;
  4. return _this.equalsExact(arg1, arg2);
  5. }

代码示例来源:origin: geoserver/geoserver

  1. @Test
  2. public void testLeaveNative() throws Exception {
  3. FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart());
  4. assertEquals("EPSG:3004", fti.getSRS());
  5. assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy());
  6. FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
  7. assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem());
  8. FeatureIterator fi = fc.features();
  9. Feature f = fi.next();
  10. // test that the geometry was left in tact
  11. Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue();
  12. assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)")));
  13. fi.close();
  14. assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem());
  15. }

代码示例来源:origin: geoserver/geoserver

  1. @Test
  2. public void testReproject() throws Exception {
  3. FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart());
  4. assertEquals("EPSG:4326", fti.getSRS());
  5. assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy());
  6. FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
  7. assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem());
  8. FeatureIterator fi = fc.features();
  9. Feature f = fi.next();
  10. // test that geometry was actually reprojected
  11. Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue();
  12. assertFalse(
  13. g.equalsExact(
  14. WKT.read(
  15. "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))")));
  16. fi.close();
  17. assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem());
  18. }

代码示例来源:origin: geoserver/geoserver

  1. @Test
  2. public void testWithRename() throws Exception {
  3. FeatureTypeInfo fti = getCatalog().getFeatureTypeByName("MyPoints");
  4. assertEquals("EPSG:4326", fti.getSRS());
  5. assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy());
  6. FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
  7. assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem());
  8. FeatureIterator fi = fc.features();
  9. Feature f = fi.next();
  10. // test that geometry was reprojected
  11. Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue();
  12. assertFalse(g.equalsExact(WKT.read("POINT(500050 500050)")));
  13. fi.close();
  14. assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem());
  15. }

代码示例来源:origin: geotools/geotools

  1. /** Compares two geometries for equality. */
  2. protected void assertEquals(Geometry expected, Geometry actual) {
  3. if (expected == actual) {
  4. return;
  5. }
  6. assertNotNull(expected);
  7. assertNotNull(actual);
  8. assertTrue(expected.equalsExact(actual));
  9. }

代码示例来源:origin: geoserver/geoserver

  1. @Test
  2. public void testGetFeaturesFeatureSource() throws Exception {
  3. // check the schemas in feature source and feature collection
  4. SimpleFeatureSource fs = rts.getFeatureSource(RENAMED);
  5. assertEquals(primitive, fs.getSchema());
  6. SimpleFeatureCollection fc = fs.getFeatures();
  7. assertEquals(primitive, fc.getSchema());
  8. assertTrue(fc.size() > 0);
  9. // make sure the feature schema is good as well
  10. FeatureIterator<SimpleFeature> it = fc.features();
  11. SimpleFeature sf = it.next();
  12. it.close();
  13. assertEquals(primitive, sf.getFeatureType());
  14. // check the feature ids have been renamed as well
  15. assertTrue(
  16. "Feature id has not been renamed, it's still " + sf.getID(),
  17. sf.getID().startsWith(RENAMED));
  18. // check mappings occurred
  19. assertEquals("description-f001", sf.getAttribute("description"));
  20. assertTrue(
  21. new WKTReader()
  22. .read("MULTIPOINT(39.73245 2.00342)")
  23. .equalsExact((Geometry) sf.getAttribute("pointProperty")));
  24. assertEquals(Long.valueOf(155), sf.getAttribute("intProperty"));
  25. assertNull(sf.getAttribute("newProperty"));
  26. }

代码示例来源:origin: geotools/geotools

  1. /** Compares two geometries for equality. */
  2. protected void assertEquals(String message, Geometry expected, Geometry actual) {
  3. if (expected == actual) {
  4. return;
  5. }
  6. assertNotNull(message, expected);
  7. assertNotNull(message, actual);
  8. assertTrue(message, expected.equalsExact(actual));
  9. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public boolean evaluateInternal(Geometry left, Geometry right) {
  3. Envelope envLeft = left.getEnvelopeInternal();
  4. Envelope envRight = right.getEnvelopeInternal();
  5. if (envRight.equals(envLeft)) return left.equalsExact(right);
  6. else return false;
  7. }

代码示例来源:origin: geotools/geotools

  1. @DescribeProcess(
  2. title = "Exactly Equal Test",
  3. description = "Tests if two geometries are identical on a vertex-by-vertex basis."
  4. )
  5. @DescribeResult(description = "True if the geometries are vertex-identical")
  6. public static boolean equalsExact(
  7. @DescribeParameter(name = "a", description = "First input geometry") Geometry a,
  8. @DescribeParameter(name = "b", description = "Second input geometry") Geometry b) {
  9. return a.equalsExact(b);
  10. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public ROI intersect(ROI roi) {
  3. final Geometry geom = getGeometry(roi);
  4. // is it a rectangle?
  5. if (geom != null && geom.equalsExact(geom.getEnvelope())) {
  6. GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal());
  7. Geometry intersect = clipper.clip(getAsGeometry(), true);
  8. return new ROIGeometry(intersect);
  9. } else {
  10. return super.intersect(roi);
  11. }
  12. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public ROI intersect(ROI roi) {
  3. final Geometry geom = getGeometry(roi);
  4. // is it a rectangle?
  5. if (geom != null && geom.equalsExact(geom.getEnvelope())) {
  6. GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal());
  7. Geometry intersect = clipper.clip(getAsGeometry(), true);
  8. return new ROIGeometry(intersect, hints);
  9. } else {
  10. return super.intersect(roi);
  11. }
  12. }

代码示例来源:origin: geotools/geotools

  1. boolean hasSameValuesAndStructure(Geometry g1, Geometry g2) {
  2. if (!g1.equalsExact(g2, ORD_TOLERANCE)) return false;
  3. if (g1.getFactory() != g2.getFactory()) return false;
  4. CoordinateSequence seq = CoordinateSequenceFinder.find(g1);
  5. if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(), seq.getDimension()))
  6. return false;
  7. return true;
  8. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testDonutCrossingInvalid() throws Exception {
  3. 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))");
  4. Geometry clipped = clipper.clip(g, false);
  5. // System.out.println(clipped);
  6. assertTrue(
  7. clipped.equalsExact(
  8. wkt.read(
  9. "POLYGON ((10 2, 10 8, 6 8, 6 2, 10 2), (10 4, 10 6, 8 6, 8 4, 10 4))")));
  10. showResult("Donut crossing, invalid geom", g, clipped);
  11. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testInsidePolygon() throws Exception {
  3. Geometry g = wkt.read("POINT(5 5)").buffer(2);
  4. Geometry clipped = clipper.clip(g, false);
  5. assertTrue(g.equalsExact(clipped));
  6. showResult("Polygon inside", g, clipped);
  7. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testDonutHoleOutside() throws Exception {
  3. Geometry g =
  4. wkt.read("POLYGON((6 2, 14 2, 14 8, 6 8, 6 2), (11 4, 12 4, 12 6, 11 6, 11 4))");
  5. Geometry clipped = clipper.clip(g, false);
  6. // System.out.println(clipped);
  7. assertTrue(clipped.equalsExact(wkt.read("POLYGON ((10 2, 10 8, 6 8, 6 2, 10 2))")));
  8. showResult("Donut crossing, invalid geom", g, clipped);
  9. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testDonutCrossingValid() throws Exception {
  3. 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))");
  4. Geometry clipped = clipper.clip(g, true);
  5. assertTrue(
  6. clipped.equalsExact(
  7. wkt.read("POLYGON ((10 2, 6 2, 6 8, 10 8, 10 6, 8 6, 8 4, 10 4, 10 2))")));
  8. showResult("Donut crossing, valid geom", g, clipped);
  9. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testTouchAndCross() throws Exception {
  3. LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 5 2, 5 3, -5 3, 0 4)");
  4. Geometry clipped = clipper.clip(ls, false);
  5. assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 5 2, 5 3, 0 3)")));
  6. showResult("Touch and cross", ls, clipped);
  7. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testTouchAndParallel() throws Exception {
  3. LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 0 2, 0 3, -5 3, 0 4)");
  4. Geometry clipped = clipper.clip(ls, false);
  5. assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 0 3)")));
  6. showResult("Touch and parallel", ls, clipped);
  7. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testPolygonCrossingThreeSides() throws Exception {
  3. Geometry g = wkt.read("POLYGON((-2 2, 12 2, 12 12, -2 12, -2 2))");
  4. Geometry clipped = clipper.clip(g, false);
  5. assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 10 2, 10 10, 0 10, 0 2))")));
  6. showResult("Crossing three sides", g, clipped);
  7. }

相关文章