[geos-commits] [SCM] GEOS branch master updated. 5ef26713f9a6b52225a593807288749399ba7fb2

git at osgeo.org git at osgeo.org
Thu Apr 11 12:11:30 PDT 2019


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  5ef26713f9a6b52225a593807288749399ba7fb2 (commit)
      from  25448d877a94df6ae8f243d617c975f3a5d67911 (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 5ef26713f9a6b52225a593807288749399ba7fb2
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Apr 11 12:11:02 2019 -0700

    IndexedFacetDistance withinDistance
    JTS 82459582ff4b410aadae3b0d143aa57528469493
    https://github.com/locationtech/jts/pull/387

diff --git a/include/geos/index/strtree/BoundablePair.h b/include/geos/index/strtree/BoundablePair.h
index cb896cd..5490705 100644
--- a/include/geos/index/strtree/BoundablePair.h
+++ b/include/geos/index/strtree/BoundablePair.h
@@ -98,6 +98,14 @@ public:
      */
     bool isLeaves() const;
 
+    /**
+     * Computes the maximum distance between any
+     * two items in the pair of nodes.
+     *
+     * @return the maximum distance between items in the pair
+     */
+    double maximumDistance();
+
     static bool isComposite(const Boundable* item);
 
     static double area(const Boundable* b);
diff --git a/include/geos/index/strtree/EnvelopeUtil.h b/include/geos/index/strtree/EnvelopeUtil.h
new file mode 100644
index 0000000..ab7ed56
--- /dev/null
+++ b/include/geos/index/strtree/EnvelopeUtil.h
@@ -0,0 +1,36 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2019 Paul Ramsey <pramsey at cleverelephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+#ifndef GEOS_INDEX_STRTREE_ENVELOPEUTIL_H
+#define GEOS_INDEX_STRTREE_ENVELOPEUTIL_H
+
+#include <geos/geom/Envelope.h>
+
+namespace geos {
+namespace index { // geos::index
+namespace strtree { // geos::index::strtree
+
+class GEOS_DLL EnvelopeUtil {
+public:
+    // EnvelopeUtil(const void* newBounds, void* newItem);
+    // ~EnvelopeUtil() override = default;
+
+    static double maximumDistance(const geom::Envelope* env1, const geom::Envelope* env2);
+
+};
+
+} // namespace geos::index::strtree
+} // namespace geos::index
+} // namespace geos
+
+#endif // GEOS_INDEX_STRTREE_ENVELOPEUTIL_H
diff --git a/include/geos/index/strtree/Makefile.am b/include/geos/index/strtree/Makefile.am
index a5e3f29..b9490cd 100644
--- a/include/geos/index/strtree/Makefile.am
+++ b/include/geos/index/strtree/Makefile.am
@@ -1,9 +1,9 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
-SUBDIRS = 
+SUBDIRS =
 
-EXTRA_DIST = 
+EXTRA_DIST =
 
 geosdir = $(includedir)/geos/index/strtree
 
@@ -12,6 +12,7 @@ geos_HEADERS = \
     AbstractSTRtree.h \
     Boundable.h \
     BoundablePair.h \
+    EnvelopeUtil.h \
     GeometryItemDistance.h \
     Interval.h \
     ItemBoundable.h \
diff --git a/include/geos/index/strtree/STRtree.h b/include/geos/index/strtree/STRtree.h
index 83d7b63..aaf5583 100644
--- a/include/geos/index/strtree/STRtree.h
+++ b/include/geos/index/strtree/STRtree.h
@@ -100,6 +100,7 @@ private:
         BoundableList* childBoundables,
         size_t sliceCount);
 
+    bool isWithinDistance(BoundablePair* initBndPair, double maxDistance);
 
 protected:
 
@@ -149,11 +150,11 @@ public:
         return AbstractSTRtree::query(searchEnv, visitor);
     }
 
+    std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
     const void* nearestNeighbour(const geom::Envelope* env, const void* item, ItemDistance* itemDist);
+    std::pair<const void*, const void*> nearestNeighbour(STRtree* tree, ItemDistance* itemDist);
     std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair);
-    std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
     std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair, double maxDistance);
-    std::pair<const void*, const void*> nearestNeighbour(STRtree* tree, ItemDistance* itemDist);
 
     bool
     remove(const geom::Envelope* itemEnv, void* item) override
@@ -161,6 +162,8 @@ public:
         return AbstractSTRtree::remove(itemEnv, item);
     }
 
+    bool isWithinDistance(STRtree* tree, ItemDistance* itemDist, double maxDistance);
+
 };
 
 } // namespace geos::index::strtree
diff --git a/src/index/strtree/BoundablePair.cpp b/src/index/strtree/BoundablePair.cpp
index 2705244..1322365 100644
--- a/src/index/strtree/BoundablePair.cpp
+++ b/src/index/strtree/BoundablePair.cpp
@@ -17,6 +17,7 @@
  **********************************************************************/
 
 #include <geos/index/strtree/BoundablePair.h>
+#include <geos/index/strtree/EnvelopeUtil.h>
 #include <geos/geom/Envelope.h>
 #include <geos/index/strtree/AbstractNode.h>
 #include <geos/util/IllegalArgumentException.h>
@@ -140,6 +141,16 @@ BoundablePair::expand(const Boundable* bndComposite, const Boundable* bndOther,
     }
 }
 
+double
+BoundablePair::maximumDistance()
+{
+    return EnvelopeUtil::maximumDistance(
+        (const geom::Envelope*) boundable1->getBounds(),
+        (const geom::Envelope*) boundable2->getBounds());
+}
+
+
+
 }
 }
 }
diff --git a/src/index/strtree/EnvelopeUtil.cpp b/src/index/strtree/EnvelopeUtil.cpp
new file mode 100644
index 0000000..1bb7d48
--- /dev/null
+++ b/src/index/strtree/EnvelopeUtil.cpp
@@ -0,0 +1,49 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2019 Paul Ramsey <pramsey at cleverelephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#include <geos/index/strtree/EnvelopeUtil.h>
+#include <geos/geom/Envelope.h>
+
+namespace geos {
+namespace index { // geos.index
+namespace strtree { // geos.index.strtree
+
+// EnvelopeUtil::EnvelopeUtil() : {}
+
+
+/*static private*/
+static double
+distance(double x1, double y1, double x2, double y2)
+{
+    double dx = x2 - x1;
+    double dy = y2 - y1;
+    return std::sqrt(dx * dx + dy * dy);
+}
+
+/*static public*/
+double
+EnvelopeUtil::maximumDistance(const geom::Envelope* env1, const geom::Envelope* env2)
+{
+    double minx = std::min(env1->getMinX(), env2->getMinX());
+    double miny = std::min(env1->getMinY(), env2->getMinY());
+    double maxx = std::max(env1->getMaxX(), env2->getMaxX());
+    double maxy = std::max(env1->getMaxY(), env2->getMaxY());
+    return distance(minx, miny, maxx, maxy);
+}
+
+
+} // namespace geos.index.strtree
+} // namespace geos.index
+} // namespace geos
+
diff --git a/src/index/strtree/Makefile.am b/src/index/strtree/Makefile.am
index 859de65..d35d510 100644
--- a/src/index/strtree/Makefile.am
+++ b/src/index/strtree/Makefile.am
@@ -1,18 +1,19 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
 noinst_LTLIBRARIES = libindexstrtree.la
 
-AM_CPPFLAGS = -I$(top_srcdir)/include 
+AM_CPPFLAGS = -I$(top_srcdir)/include
 
 libindexstrtree_la_SOURCES = \
     AbstractNode.cpp \
     AbstractSTRtree.cpp \
     BoundablePair.cpp \
+    EnvelopeUtil.cpp \
     GeometryItemDistance.cpp \
     Interval.cpp \
     ItemBoundable.cpp \
     SIRtree.cpp \
     STRtree.cpp
 
-libindexstrtree_la_LIBADD = 
+libindexstrtree_la_LIBADD =
diff --git a/src/index/strtree/STRtree.cpp b/src/index/strtree/STRtree.cpp
index faaf29f..c03247e 100644
--- a/src/index/strtree/STRtree.cpp
+++ b/src/index/strtree/STRtree.cpp
@@ -183,6 +183,14 @@ STRtree::verticalSlices(BoundableList* childBoundables, size_t sliceCount)
 }
 
 /*public*/
+std::pair<const void*, const void*>
+STRtree::nearestNeighbour(ItemDistance* itemDist)
+{
+    BoundablePair bp(this->getRoot(), this->getRoot(), itemDist);
+    return nearestNeighbour(&bp);
+}
+
+/*public*/
 const void*
 STRtree::nearestNeighbour(const Envelope* env, const void* item, ItemDistance* itemDist)
 {
@@ -194,26 +202,22 @@ STRtree::nearestNeighbour(const Envelope* env, const void* item, ItemDistance* i
     return nearestNeighbour(&bp).first;
 }
 
+/*public*/
 std::pair<const void*, const void*>
-STRtree::nearestNeighbour(BoundablePair* initBndPair)
-{
-    return nearestNeighbour(initBndPair, std::numeric_limits<double>::infinity());
-}
-
-std::pair<const void*, const void*>
-STRtree::nearestNeighbour(ItemDistance* itemDist)
+STRtree::nearestNeighbour(STRtree* tree, ItemDistance* itemDist)
 {
-    BoundablePair bp(this->getRoot(), this->getRoot(), itemDist);
+    BoundablePair bp(getRoot(), tree->getRoot(), itemDist);
     return nearestNeighbour(&bp);
 }
 
+/*public*/
 std::pair<const void*, const void*>
-STRtree::nearestNeighbour(STRtree* tree, ItemDistance* itemDist)
+STRtree::nearestNeighbour(BoundablePair* initBndPair)
 {
-    BoundablePair bp(getRoot(), tree->getRoot(), itemDist);
-    return nearestNeighbour(&bp);
+    return nearestNeighbour(initBndPair, std::numeric_limits<double>::infinity());
 }
 
+/*public*/
 std::pair<const void*, const void*>
 STRtree::nearestNeighbour(BoundablePair* initBndPair, double maxDistance)
 {
@@ -287,6 +291,74 @@ STRtree::nearestNeighbour(BoundablePair* initBndPair, double maxDistance)
     return std::pair<const void*, const void*>(item0, item1);
 }
 
+/*public*/
+bool
+STRtree::isWithinDistance(STRtree* tree, ItemDistance* itemDist, double maxDistance)
+{
+    BoundablePair bp(getRoot(), tree->getRoot(), itemDist);
+    return isWithinDistance(&bp, maxDistance);
+}
+
+/*private*/
+bool STRtree::isWithinDistance(BoundablePair* initBndPair, double maxDistance)
+{
+    double distanceUpperBound = std::numeric_limits<double>::infinity();
+
+    // initialize search queue
+    BoundablePair::BoundablePairQueue priQ;
+    priQ.push(initBndPair);
+
+    while(!priQ.empty()) {
+        BoundablePair* bndPair = priQ.top();
+        double currentDistance = bndPair->getDistance();
+
+        /**
+        * If the distance for the first pair in the queue
+        * is >= maxDistance, other pairs
+        * in the queue must also have a greater distance.
+        * So can conclude no items are within the distance
+        * and terminate with false
+        */
+        if (currentDistance > maxDistance)
+            return false;
+
+        /**
+        * There must be some pair of items in the nodes which
+        * are closer than the max distance,
+        * so can terminate with true.
+        *
+        * NOTE: using the Envelope MinMaxDistance would provide a tighter bound,
+        * but not sure how to compute this!
+        */
+        if (bndPair->maximumDistance() <= maxDistance)
+            return true;
+
+        /**
+        * If the pair members are leaves
+        * then their distance is an upper bound.
+        * Update the distanceUpperBound to reflect this
+        */
+        if (bndPair->isLeaves()) {
+            distanceUpperBound = currentDistance;
+
+            // Current pair is closer than maxDistance
+            // so can terminate with true
+            if (distanceUpperBound <= maxDistance)
+                return true;
+        }
+        else {
+            /**
+            * Otherwise, expand one side of the pair,
+            * and insert the expanded pairs into the queue.
+            * The choice of which side to expand is determined heuristically.
+            */
+            bndPair->expandToQueue(priQ, distanceUpperBound);
+        }
+    }
+    return false;
+}
+
+
 class STRAbstractNode: public AbstractNode {
 public:
 

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

Summary of changes:
 include/geos/index/strtree/BoundablePair.h         |  8 ++
 .../index/strtree/{Interval.h => EnvelopeUtil.h}   | 31 +++----
 include/geos/index/strtree/Makefile.am             |  7 +-
 include/geos/index/strtree/STRtree.h               |  7 +-
 src/index/strtree/BoundablePair.cpp                | 11 +++
 src/index/strtree/EnvelopeUtil.cpp                 | 49 +++++++++++
 src/index/strtree/Makefile.am                      |  7 +-
 src/index/strtree/STRtree.cpp                      | 94 +++++++++++++++++++---
 8 files changed, 175 insertions(+), 39 deletions(-)
 copy include/geos/index/strtree/{Interval.h => EnvelopeUtil.h} (53%)
 create mode 100644 src/index/strtree/EnvelopeUtil.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list