[geos-commits] [SCM] GEOS branch master updated. 07e60468a9a155c63b06fa1e24db7c113f03004a

git at osgeo.org git at osgeo.org
Fri Nov 6 11:08:19 PST 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  07e60468a9a155c63b06fa1e24db7c113f03004a (commit)
      from  fa24fb2f3bd84cd70309f8594aa29738661e94ca (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 07e60468a9a155c63b06fa1e24db7c113f03004a
Author: sumeerbhola <sumeer at cockroachlabs.com>
Date:   Wed Sep 2 09:45:45 2020 -0400

    Fix segfault in SimplePointInAreaLocator caused by casting MultiPolygon to Polygon
    
    Closes #1047
    References https://github.com/cockroachdb/cockroach/issues/53254
    
    Signed-off-by: Sandro Santilli <strk at kbt.io>

diff --git a/src/algorithm/locate/SimplePointInAreaLocator.cpp b/src/algorithm/locate/SimplePointInAreaLocator.cpp
index e6ba6b2..df3a39e 100644
--- a/src/algorithm/locate/SimplePointInAreaLocator.cpp
+++ b/src/algorithm/locate/SimplePointInAreaLocator.cpp
@@ -67,15 +67,17 @@ SimplePointInAreaLocator::locateInGeometry(const Coordinate& p, const Geometry*
     }
 
     if (geom->getNumGeometries() == 1) {
-        return locatePointInPolygon(p, dynamic_cast<const Polygon*>(geom->getGeometryN(0)));
-    } else {
-        for (size_t i = 0; i < geom->getNumGeometries(); i++) {
-            const Geometry* gi = geom->getGeometryN(i);
-
-            auto loc = locateInGeometry(p, gi);
-            if(loc != Location::EXTERIOR) {
-                return loc;
-            }
+        auto poly = dynamic_cast<const Polygon*>(geom->getGeometryN(0));
+        if (poly) {
+            return locatePointInPolygon(p, poly);
+        }
+        // Else it is a collection with a single element. Will be handled below.
+    }
+    for (size_t i = 0; i < geom->getNumGeometries(); i++) {
+        const Geometry* gi = geom->getGeometryN(i);
+        auto loc = locateInGeometry(p, gi);
+        if(loc != Location::EXTERIOR) {
+            return loc;
         }
     }
 
diff --git a/tests/unit/algorithm/PointLocatorTest.cpp b/tests/unit/algorithm/PointLocatorTest.cpp
index bc63b07..a230d96 100644
--- a/tests/unit/algorithm/PointLocatorTest.cpp
+++ b/tests/unit/algorithm/PointLocatorTest.cpp
@@ -5,6 +5,7 @@
 #include <tut/tut.hpp>
 // geos
 #include <geos/io/WKTReader.h>
+#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
 #include <geos/algorithm/PointLocator.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
@@ -56,6 +57,14 @@ runPtLocator(Location expected, const Coordinate& pt,
     ensure_equals(loc, expected);
 }
 
+void
+runSimplePtLocator(Location expected, const Coordinate& pt,
+             const std::string& wkt)
+{
+    GeomPtr geom(reader.read(wkt));
+    Location loc = geos::algorithm::locate::SimplePointInAreaLocator::locate(pt, geom.get());
+    ensure_equals(loc, expected);
+}
 
 //
 // Test Cases
@@ -111,5 +120,15 @@ void object::test<5>
                  "MULTIPOINT ((1 1), (0 0))");
 }
 
+// 6 - TestPointLocator Point inside GeometryCollection containing MultiPolygon, using SimplePointInAreaLocator.
+template<>
+template<>
+void object::test<6>
+()
+{
+    runSimplePtLocator(Location::INTERIOR, Coordinate(0, 0),
+                       "GEOMETRYCOLLECTION (MULTIPOLYGON (((-1 -1, 1 -1, 1 1, -1 1, -1 -1))))");
+}
+
 } // namespace tut
 

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

Summary of changes:
 src/algorithm/locate/SimplePointInAreaLocator.cpp | 20 +++++++++++---------
 tests/unit/algorithm/PointLocatorTest.cpp         | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list