[geos-commits] [SCM] GEOS branch master updated. 2e033c754f2767be3d718b0cfcce7b1ed3290a66

git at osgeo.org git at osgeo.org
Tue Sep 15 13:21:32 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  2e033c754f2767be3d718b0cfcce7b1ed3290a66 (commit)
      from  ab1e0351984663da5852d1c05df86d175baf54bd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2e033c754f2767be3d718b0cfcce7b1ed3290a66
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Sep 15 13:21:23 2020 -0700

    Move OverlayNGSnapIfNeeded out of Geometry and into HeuristicOverlay.
    Move OverlayNGSnapIfNeeded to the front of the heuristic list, if its turned on, as it subsumes the behaviour in all the
    other heuristics.

diff --git a/include/geos/operation/union/UnaryUnionOp.h b/include/geos/operation/union/UnaryUnionOp.h
index 049cf80..0ba3de9 100644
--- a/include/geos/operation/union/UnaryUnionOp.h
+++ b/include/geos/operation/union/UnaryUnionOp.h
@@ -24,7 +24,6 @@
 
 #include <geos/export.h>
 #include <geos/geom/GeometryFactory.h>
-#include <geos/geom/HeuristicOverlay.h>
 #include <geos/geom/Point.h>
 #include <geos/geom/LineString.h>
 #include <geos/geom/Polygon.h>
diff --git a/src/geom/Geometry.cpp b/src/geom/Geometry.cpp
index 6a1075a..966657c 100644
--- a/src/geom/Geometry.cpp
+++ b/src/geom/Geometry.cpp
@@ -551,11 +551,7 @@ Geometry::intersection(const Geometry* other) const
     }
 #endif
 
-#ifdef USE_OVERLAYNG
-    return operation::overlayng::OverlayNGSnapIfNeeded::Intersection(this, other);
-#else
     return HeuristicOverlay(this, other, OverlayOp::opINTERSECTION);
-#endif
 }
 
 std::unique_ptr<Geometry>
@@ -609,11 +605,7 @@ Geometry::Union(const Geometry* other) const
     }
 #endif
 
-#ifdef USE_OVERLAYNG
-    return operation::overlayng::OverlayNGSnapIfNeeded::Union(this, other);
-#else
     return HeuristicOverlay(this, other, OverlayOp::opUNION);
-#endif
 }
 
 /* public */
@@ -640,11 +632,7 @@ Geometry::difference(const Geometry* other) const
         return clone();
     }
 
-#ifdef USE_OVERLAYNG
-    return operation::overlayng::OverlayNGSnapIfNeeded::Difference(this, other);
-#else
     return HeuristicOverlay(this, other, OverlayOp::opDIFFERENCE);
-#endif
 }
 
 std::unique_ptr<Geometry>
@@ -694,11 +682,7 @@ Geometry::symDifference(const Geometry* other) const
         return std::unique_ptr<Geometry>(_factory->buildGeometry(v));
     }
 
-#ifdef USE_OVERLAYNG
-    return operation::overlayng::OverlayNGSnapIfNeeded::SymDifference(this, other);
-#else
     return HeuristicOverlay(this, other, OverlayOp::opSYMDIFFERENCE);
-#endif
 
 }
 
diff --git a/src/geom/HeuristicOverlay.cpp b/src/geom/HeuristicOverlay.cpp
index 0e8bbf2..8ea3e0e 100644
--- a/src/geom/HeuristicOverlay.cpp
+++ b/src/geom/HeuristicOverlay.cpp
@@ -30,11 +30,11 @@
  * slightly modified versions of the input. The following heuristic
  * is used:
  *
- *	- Try with original input.
- *	- Try removing common bits from input coordinate values
- *	- Try snaping input geometries to each other
- *	- Try snaping input coordinates to a increasing grid (size from 1/25 to 1)
- *	- Try simplifiying input with increasing tolerance (from 0.01 to 0.04)
+ *  - Try with original input.
+ *  - Try removing common bits from input coordinate values
+ *  - Try snaping input geometries to each other
+ *  - Try snaping input coordinates to a increasing grid (size from 1/25 to 1)
+ *  - Try simplifiying input with increasing tolerance (from 0.01 to 0.04)
  *
  * If none of the step succeeds the original exception is thrown.
  *
@@ -82,6 +82,13 @@
 
 
 /*
+ * Define this to use OverlayNG policy with whatever precision
+ */
+#if ! defined(USE_OVERLAYNG_SNAPIFNEEDED) && defined(USE_OVERLAYNG)
+# define USE_OVERLAYNG_SNAPIFNEEDED
+#endif
+
+/*
  * Always try original input first
  */
 #ifndef USE_ORIGINAL_INPUT
@@ -101,14 +108,6 @@
 #endif
 
 /*
- * Define this to use OverlayNG policy with whatever precision
- */
-#ifndef USE_OVERLAYNG_SNAPIFNEEDED
-# define USE_OVERLAYNG_SNAPIFNEEDED 0
-#endif
-
-
-/*
  * Define this to use PrecisionReduction policy
  * in an attempt at by-passing binary operation
  * robustness problems (handles TopologyExceptions)
@@ -368,6 +367,71 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
     GeomPtr ret;
     geos::util::TopologyException origException;
 
+
+/**************************************************************************/
+
+/*
+* overlayng::OverlayNGSnapIfNeeded carries out the following steps
+*
+* 1. Perform overlay operation using PrecisionModel(float).
+*    If no exception return result.
+* 2. Perform overlay operation using SnappingNoder(tolerance), starting
+*    with a very very small tolerance and increasing it for 5 iterations.
+*    The SnappingNoder moves only nodes that are within tolerance of
+*    other nodes and lines, leaving all the rest undisturbed, for a very
+*    clean result, if it manages to create one.
+*    If a result is found with no exception, return.
+* 3. Peform overlay operation using a PrecisionModel(scale), which
+*    uses a SnapRoundingNoder. Every vertex will be noded to the snapping
+*    grid, resulting in a modified geometry. The SnapRoundingNoder approach
+*    reliably produces results, assuming valid inputs.
+*
+* Running overlayng::OverlayNGSnapIfNeeded at this stage should guarantee
+* that none of the other heuristics are ever needed.
+*/
+#ifdef USE_OVERLAYNG_SNAPIFNEEDED
+
+#if GEOS_DEBUG_HEURISTICOVERLAY
+    std::cerr << "Trying with OverlayNGSnapIfNeeded" << std::endl;
+#endif
+
+    try {
+        if (g0 == nullptr && g1 == nullptr) {
+            return std::unique_ptr<Geometry>(nullptr);
+        }
+        else if (g0 == nullptr) {
+            // Use a uniary union for the one-parameter case, as the pairwise
+            // union with one parameter is very intolerant to invalid
+            // collections and multi-polygons.
+            ret = operation::overlayng::OverlayNGSnapIfNeeded::Union(g1);
+        }
+        else if (g1 == nullptr) {
+            // Use a uniary union for the one-parameter case, as the pairwise
+            // union with one parameter is very intolerant to invalid
+            // collections and multi-polygons.
+            ret = operation::overlayng::OverlayNGSnapIfNeeded::Union(g0);
+        }
+        else {
+            ret = operation::overlayng::OverlayNGSnapIfNeeded::Overlay(g0, g1, opCode);
+        }
+
+#if GEOS_DEBUG_HEURISTICOVERLAY
+        std::cerr << "Attempt with OverlayNGSnapIfNeeded succeeded" << std::endl;
+#endif
+
+        return ret;
+    }
+    catch(const geos::util::TopologyException& ex) {
+        ::geos::ignore_unused_variable_warning(ex);
+#if GEOS_DEBUG_HEURISTICOVERLAY
+        std::cerr << "OverlayNGSnapIfNeeded: " << ex.what() << std::endl;
+#endif
+    }
+#endif // USE_OVERLAYNG_SNAPIFNEEDED }
+
+
+/**************************************************************************/
+
 #ifdef USE_ORIGINAL_INPUT
     // Try with original input
     try {
@@ -393,6 +457,8 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
     }
 #endif // USE_ORIGINAL_INPUT
 
+/**************************************************************************/
+
     check_valid(*g0, "Input geom 0", true, true);
     check_valid(*g1, "Input geom 1", true, true);
 
@@ -453,12 +519,14 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
     }
 #endif
 
-    // Try with snapping
-    //
-    // TODO: possible optimization would be reusing the
-    //       already common-bit-removed inputs and just
-    //       apply geometry snapping, whereas the current
-    //       SnapOp function does both.
+/**************************************************************************/
+
+// Try with snapping
+//
+// TODO: possible optimization would be reusing the
+//       already common-bit-removed inputs and just
+//       apply geometry snapping, whereas the current
+//       SnapOp function does both.
 // {
 #if USE_SNAPPING_POLICY
 
@@ -486,6 +554,7 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
 
 #endif // USE_SNAPPING_POLICY }
 
+/**************************************************************************/
 
 // {
 #if USE_PRECISION_REDUCTION_POLICY
@@ -578,10 +647,11 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
 #endif
 // USE_PRECISION_REDUCTION_POLICY }
 
+/**************************************************************************/
+
 // {
 #if USE_FIXED_PRECISION_OVERLAYNG
 
-
     // Try OverlayNG with fixed precision
     try {
         long unsigned int g0scale =
@@ -646,6 +716,7 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
 #endif
 // USE_FIXED_PRECISION_OVERLAYNG }
 
+/**************************************************************************/
 
 // {
 #if USE_TP_SIMPLIFY_POLICY
@@ -693,31 +764,7 @@ HeuristicOverlay(const Geometry* g0, const Geometry* g1, int opCode)
 #endif
 // USE_TP_SIMPLIFY_POLICY }
 
-
-// {
-#if USE_OVERLAYNG_SNAPIFNEEDED
-
-#if GEOS_DEBUG_HEURISTICOVERLAY
-    std::cerr << "Trying with OverlayNGSnapIfNeeded" << std::endl;
-#endif
-
-    try {
-        ret = operation::overlayng::OverlayNGSnapIfNeeded::Overlay(g0, g1, opCode);
-
-#if GEOS_DEBUG_HEURISTICOVERLAY
-        std::cerr << "Attempt with OverlayNGSnapIfNeeded succeeded" << std::endl;
-#endif
-
-        return ret;
-    }
-    catch(const geos::util::TopologyException& ex) {
-        ::geos::ignore_unused_variable_warning(ex);
-#if GEOS_DEBUG_HEURISTICOVERLAY
-        std::cerr << "OverlayNGSnapIfNeeded: " << ex.what() << std::endl;
-#endif
-    }
-#endif // USE_OVERLAYNG_SNAPIFNEEDED }
-
+/**************************************************************************/
 
 #if GEOS_DEBUG_HEURISTICOVERLAY
     std::cerr << "No attempts worked to union " << std::endl;

-----------------------------------------------------------------------

Summary of changes:
 include/geos/operation/union/UnaryUnionOp.h |   1 -
 src/geom/Geometry.cpp                       |  16 ----
 src/geom/HeuristicOverlay.cpp               | 137 +++++++++++++++++++---------
 3 files changed, 92 insertions(+), 62 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list