[geos-commits] [SCM] GEOS branch master updated. 7d4e17336f45d39aa2debd91237eed461aa5da09

git at osgeo.org git at osgeo.org
Thu Nov 26 13:01:29 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  7d4e17336f45d39aa2debd91237eed461aa5da09 (commit)
       via  0dcb3214ee06a42d61f6ae6fe4798039a5fb7961 (commit)
      from  352d07a45ea4d7b8a17962e7d02ba9a69dce891d (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 7d4e17336f45d39aa2debd91237eed461aa5da09
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Nov 26 13:01:09 2020 -0800

    Note that SimpleSTRtree is now the tree used in the C API

diff --git a/NEWS b/NEWS
index 3f2a081..01de82a 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Changes in 3.9.0
   - CAPI: GEOSPreparedNearestPoints (#1007, Sandro Santilli)
   - CAPI: GEOSPreparedDistance (#1066, Sandro Santilli)
   - SimpleSTRTree spatial index implementation (Paul Ramsey)
+  - SimpleSTRTree used for C API (Paul Ramsey)
 
 - Improvements:
   - Stack allocate segments in OverlapUnion (Paul Ramsey)

commit 0dcb3214ee06a42d61f6ae6fe4798039a5fb7961
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Nov 26 12:59:56 2020 -0800

    Change CAPI STRTree functions to use the SimpleSTRtree so
    that third parties can also get the performance win of the
    new tree.

diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index 44fb257..9cfa0b0 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -70,7 +70,6 @@ using geos::io::WKTWriter;
 using geos::io::WKBReader;
 using geos::io::WKBWriter;
 
-using geos::index::strtree::STRtree;
 
 
 typedef std::unique_ptr<Geometry> GeomPtr;
@@ -1311,14 +1310,14 @@ extern "C" {
         return GEOSPreparedDistance_r(handle, g1, g2, dist);
     }
 
-    STRtree*
+    GEOSSTRtree*
     GEOSSTRtree_create(size_t nodeCapacity)
     {
         return GEOSSTRtree_create_r(handle, nodeCapacity);
     }
 
     void
-    GEOSSTRtree_insert(geos::index::strtree::STRtree* tree,
+    GEOSSTRtree_insert(GEOSSTRtree* tree,
                        const geos::geom::Geometry* g,
                        void* item)
     {
@@ -1326,7 +1325,7 @@ extern "C" {
     }
 
     void
-    GEOSSTRtree_query(geos::index::strtree::STRtree* tree,
+    GEOSSTRtree_query(GEOSSTRtree* tree,
                       const geos::geom::Geometry* g,
                       GEOSQueryCallback cb,
                       void* userdata)
@@ -1335,7 +1334,7 @@ extern "C" {
     }
 
     const GEOSGeometry*
-    GEOSSTRtree_nearest(geos::index::strtree::STRtree* tree,
+    GEOSSTRtree_nearest(GEOSSTRtree* tree,
                         const geos::geom::Geometry* g)
     {
         return GEOSSTRtree_nearest_r(handle, tree, g);
@@ -1351,7 +1350,7 @@ extern "C" {
     }
 
     void
-    GEOSSTRtree_iterate(geos::index::strtree::STRtree* tree,
+    GEOSSTRtree_iterate(GEOSSTRtree* tree,
                         GEOSQueryCallback callback,
                         void* userdata)
     {
@@ -1359,7 +1358,7 @@ extern "C" {
     }
 
     char
-    GEOSSTRtree_remove(geos::index::strtree::STRtree* tree,
+    GEOSSTRtree_remove(GEOSSTRtree* tree,
                        const geos::geom::Geometry* g,
                        void* item)
     {
@@ -1367,7 +1366,7 @@ extern "C" {
     }
 
     void
-    GEOSSTRtree_destroy(geos::index::strtree::STRtree* tree)
+    GEOSSTRtree_destroy(GEOSSTRtree* tree)
     {
         GEOSSTRtree_destroy_r(handle, tree);
     }
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index b13a6e0..6bf1240 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -37,7 +37,7 @@
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/IntersectionMatrix.h>
 #include <geos/geom/Envelope.h>
-#include <geos/index/strtree/STRtree.h>
+#include <geos/index/strtree/SimpleSTRtree.h>
 #include <geos/index/strtree/GeometryItemDistance.h>
 #include <geos/index/ItemVisitor.h>
 #include <geos/io/WKTReader.h>
@@ -112,7 +112,7 @@
 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
 #define GEOSCoordSequence geos::geom::CoordinateSequence
 #define GEOSBufferParams geos::operation::buffer::BufferParameters
-#define GEOSSTRtree geos::index::strtree::STRtree
+#define GEOSSTRtree geos::index::strtree::SimpleSTRtree
 #define GEOSWKTReader_t geos::io::WKTReader
 #define GEOSWKTWriter_t geos::io::WKTWriter
 #define GEOSWKBReader_t geos::io::WKBReader
@@ -2966,18 +2966,18 @@ extern "C" {
 // STRtree
 //-----------------------------------------------------------------
 
-    geos::index::strtree::STRtree*
+    GEOSSTRtree*
     GEOSSTRtree_create_r(GEOSContextHandle_t extHandle,
                          size_t nodeCapacity)
     {
         return execute(extHandle, [&]() {
-            return new geos::index::strtree::STRtree(nodeCapacity);
+            return new GEOSSTRtree(nodeCapacity);
         });
     }
 
     void
     GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle,
-                         geos::index::strtree::STRtree* tree,
+                         GEOSSTRtree* tree,
                          const geos::geom::Geometry* g,
                          void* item)
     {
@@ -2988,7 +2988,7 @@ extern "C" {
 
     void
     GEOSSTRtree_query_r(GEOSContextHandle_t extHandle,
-                        geos::index::strtree::STRtree* tree,
+                        GEOSSTRtree* tree,
                         const geos::geom::Geometry* g,
                         GEOSQueryCallback callback,
                         void* userdata)
@@ -3001,7 +3001,7 @@ extern "C" {
 
     const GEOSGeometry*
     GEOSSTRtree_nearest_r(GEOSContextHandle_t extHandle,
-                          geos::index::strtree::STRtree* tree,
+                          GEOSSTRtree* tree,
                           const geos::geom::Geometry* geom)
     {
         return (const GEOSGeometry*) GEOSSTRtree_nearest_generic_r(extHandle, tree, geom, geom, nullptr, nullptr);
@@ -3009,7 +3009,7 @@ extern "C" {
 
     const void*
     GEOSSTRtree_nearest_generic_r(GEOSContextHandle_t extHandle,
-                                  geos::index::strtree::STRtree* tree,
+                                  GEOSSTRtree* tree,
                                   const void* item,
                                   const geos::geom::Geometry* itemEnvelope,
                                   GEOSDistanceCallback distancefn,
@@ -3053,7 +3053,7 @@ extern "C" {
 
     void
     GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle,
-                          geos::index::strtree::STRtree* tree,
+                          GEOSSTRtree* tree,
                           GEOSQueryCallback callback,
                           void* userdata)
     {
@@ -3065,7 +3065,7 @@ extern "C" {
 
     char
     GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle,
-                         geos::index::strtree::STRtree* tree,
+                         GEOSSTRtree* tree,
                          const geos::geom::Geometry* g,
                          void* item) {
         return execute(extHandle, 2, [&]() {
@@ -3075,7 +3075,7 @@ extern "C" {
 
     void
     GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle,
-                          geos::index::strtree::STRtree* tree)
+                          GEOSSTRtree* tree)
     {
         return execute(extHandle, [&]() {
             delete tree;
diff --git a/include/geos/index/strtree/SimpleSTRtree.h b/include/geos/index/strtree/SimpleSTRtree.h
index baf79a4..6baa271 100644
--- a/include/geos/index/strtree/SimpleSTRtree.h
+++ b/include/geos/index/strtree/SimpleSTRtree.h
@@ -140,6 +140,8 @@ public:
 
     void insert(const geom::Envelope* itemEnv, void* item) override;
 
+    void iterate(ItemVisitor& visitor);
+
     void query(const geom::Envelope* searchEnv, std::vector<void*>& matches) override;
 
     void query(const geom::Envelope* searchEnv, ItemVisitor& visitor) override;
diff --git a/src/index/strtree/SimpleSTRtree.cpp b/src/index/strtree/SimpleSTRtree.cpp
index 1dbf20e..b8724e1 100644
--- a/src/index/strtree/SimpleSTRtree.cpp
+++ b/src/index/strtree/SimpleSTRtree.cpp
@@ -17,6 +17,7 @@
 #include <geos/index/ItemVisitor.h>
 #include <geos/geom/Envelope.h>
 #include <geos/geom/Geometry.h>
+#include <geos/util.h>
 
 #include <vector>
 #include <cassert>
@@ -59,6 +60,8 @@ SimpleSTRtree::insert(geom::Geometry* geom)
 void
 SimpleSTRtree::insert(const geom::Envelope* itemEnv, void* item)
 {
+    if (itemEnv->isNull())
+        return;
     SimpleSTRnode *node = createNode(0, itemEnv, item);
     nodes.push_back(node);
 }
@@ -175,7 +178,7 @@ SimpleSTRtree::build()
     if (built) return;
 
     if (nodes.empty()) {
-        root = createNode(0);
+        root = nullptr;
     }
     else {
         std::vector<SimpleSTRnode*> nodeTree = createHigherLevels(nodes, -1);
@@ -185,16 +188,21 @@ SimpleSTRtree::build()
     built = true;
 }
 
+void
+SimpleSTRtree::iterate(ItemVisitor& visitor)
+{
+    for(auto* leafNode: nodes) {
+        visitor.visitItem(leafNode->getItem());
+    }
+}
+
 /* public */
 void
 SimpleSTRtree::query(const geom::Envelope* searchEnv, ItemVisitor& visitor)
 {
-    if(!built) {
-        build();
-    }
+    build();
 
-    if(nodes.empty()) {
-        assert(root == nullptr);
+    if(nodes.empty() || !root) {
         return;
     }
 
@@ -226,12 +234,9 @@ SimpleSTRtree::query(const geom::Envelope* searchEnv,
 void
 SimpleSTRtree::query(const geom::Envelope* searchEnv, std::vector<void*>& matches)
 {
-    if(!built) {
-        build();
-    }
+    build();
 
-    if(nodes.empty()) {
-        assert(root == nullptr);
+    if(nodes.empty() || !root) {
         return;
     }
 
@@ -265,10 +270,9 @@ SimpleSTRtree::query(const geom::Envelope* searchEnv,
 bool
 SimpleSTRtree::remove(const geom::Envelope* itemEnv, void* item)
 {
-    if (itemEnv || item) // no implementation of remove() yet!
-        return false;
-    else
-        return false;
+    ::geos::ignore_unused_variable_warning(itemEnv);
+    ::geos::ignore_unused_variable_warning(item);
+    assert(false);
 }
 
 
@@ -280,10 +284,15 @@ operator<<(std::ostream& os, SimpleSTRtree& tree)
     os << "nodeCapacity: " << tree.getNodeCapacity() << std::endl;
     os << "nodes.size(): " << tree.getNumLeafNodes() << std::endl;
     os << "built: " << tree.getBuilt() << std::endl;
-    os << "tree: " << std::endl;
 
-    if (tree.getRoot())
+
+    if (tree.getRoot()) {
+        os << "tree: " << std::endl;
         tree.getRoot()->toString(os, 1);
+    }
+    else {
+        os << "tree: empty" << std::endl;
+    }
     return os;
 }
 
@@ -293,6 +302,9 @@ operator<<(std::ostream& os, SimpleSTRtree& tree)
 std::pair<const void*, const void*>
 SimpleSTRtree::nearestNeighbour(ItemDistance* itemDist)
 {
+    if (!this->getRoot()) {
+        return std::pair<const void*, const void*>(nullptr, nullptr);
+    }
     SimpleSTRdistance strDist(this->getRoot(), this->getRoot(), itemDist);
     return strDist.nearestNeighbour();
 }
@@ -302,6 +314,9 @@ SimpleSTRtree::nearestNeighbour(ItemDistance* itemDist)
 const void*
 SimpleSTRtree::nearestNeighbour(const geom::Envelope* p_env, const void* p_item, ItemDistance* itemDist)
 {
+    if (!this->getRoot()) {
+        return nullptr;
+    }
     std::unique_ptr<SimpleSTRnode> ssn(new SimpleSTRnode(0, p_env, (void*)p_item));
     SimpleSTRdistance strDist(getRoot(), ssn.get(), itemDist);
     std::pair<const void*, const void*> result = strDist.nearestNeighbour();
@@ -313,6 +328,9 @@ SimpleSTRtree::nearestNeighbour(const geom::Envelope* p_env, const void* p_item,
 std::pair<const void*, const void*>
 SimpleSTRtree::nearestNeighbour(SimpleSTRtree& tree, ItemDistance* itemDist)
 {
+    if (!(this->getRoot() && tree.getRoot())) {
+        return std::pair<const void*, const void*>(nullptr, nullptr);
+    }
     SimpleSTRdistance strDist(this->getRoot(), tree.getRoot(), itemDist);
     return strDist.nearestNeighbour();
 }
@@ -321,6 +339,9 @@ SimpleSTRtree::nearestNeighbour(SimpleSTRtree& tree, ItemDistance* itemDist)
 bool
 SimpleSTRtree::isWithinDistance(SimpleSTRtree& tree, ItemDistance* itemDist, double maxDistance)
 {
+    if (!(this->getRoot() && tree.getRoot())) {
+        return false;
+    }
     SimpleSTRdistance strDist(this->getRoot(), tree.getRoot(), itemDist);
     return strDist.isWithinDistance(maxDistance);
 }

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

Summary of changes:
 NEWS                                       |  1 +
 capi/geos_c.cpp                            | 15 ++++----
 capi/geos_ts_c.cpp                         | 22 ++++++------
 include/geos/index/strtree/SimpleSTRtree.h |  2 ++
 src/index/strtree/SimpleSTRtree.cpp        | 55 +++++++++++++++++++++---------
 5 files changed, 59 insertions(+), 36 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list