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

git at osgeo.org git at osgeo.org
Wed Nov 18 11:43:18 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  5ffe865a2b2ee253901ca207dd2e77f30476faaf (commit)
       via  ff3e488850af6f8837842ea60d24dbf99773a632 (commit)
      from  f14b2da0ff282d1bdd6b3dafd17783acca1c1938 (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 5ffe865a2b2ee253901ca207dd2e77f30476faaf
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Nov 18 11:43:04 2020 -0800

    SimpleSTRtree autotools build.

diff --git a/include/geos/index/strtree/Makefile.am b/include/geos/index/strtree/Makefile.am
index b9490cd..2f9191e 100644
--- a/include/geos/index/strtree/Makefile.am
+++ b/include/geos/index/strtree/Makefile.am
@@ -18,4 +18,6 @@ geos_HEADERS = \
     ItemBoundable.h \
     ItemDistance.h \
     SIRtree.h \
-    STRtree.h
+    STRtree.h \
+    SimpleSTRtree.h \
+    SimpleSTRnode.h
diff --git a/src/index/strtree/Makefile.am b/src/index/strtree/Makefile.am
index 64227b5..4f3d773 100644
--- a/src/index/strtree/Makefile.am
+++ b/src/index/strtree/Makefile.am
@@ -12,6 +12,8 @@ libindexstrtree_la_SOURCES = \
     GeometryItemDistance.cpp \
     Interval.cpp \
     SIRtree.cpp \
-    STRtree.cpp
+    STRtree.cpp \
+    SimpleSTRtree.cpp \
+    SimpleSTRnode.cpp
 
 libindexstrtree_la_LIBADD =
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 505fb96..190d04c 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -158,6 +158,7 @@ geos_unit_SOURCES = \
 	geom/TriangleTest.cpp \
 	geom/util/GeometryExtracterTest.cpp \
 	index/strtree/SIRtreeTest.cpp \
+	index/strtree/SimpeSTRtreeTest.cpp \
 	index/kdtree/KdTreeTest.cpp \
 	io/ByteOrderValuesTest.cpp \
 	io/WKBReaderTest.cpp \

commit ff3e488850af6f8837842ea60d24dbf99773a632
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Wed Nov 18 11:38:56 2020 -0800

    SimpleSTRtree implementation. Functionally the same as STRtree,
    but without the extra layer of abstraction with AbstractSTRtree.
    Take advantage of simpler inheritance to also avoid heap allocations,
    and to store node envelope information close together and
    promote memory locality, hopefully better CPU efficiency and
    cache coherence.

diff --git a/NEWS b/NEWS
index 5e70eab..3f2a081 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Changes in 3.9.0
   - CAPI: Fixed precision overlay operations (Sandro Santilli, Paul Ramsey)
   - CAPI: GEOSPreparedNearestPoints (#1007, Sandro Santilli)
   - CAPI: GEOSPreparedDistance (#1066, Sandro Santilli)
+  - SimpleSTRTree spatial index implementation (Paul Ramsey)
 
 - Improvements:
   - Stack allocate segments in OverlapUnion (Paul Ramsey)
diff --git a/include/geos/geom/Envelope.h b/include/geos/geom/Envelope.h
index ba8459a..1f02aca 100644
--- a/include/geos/geom/Envelope.h
+++ b/include/geos/geom/Envelope.h
@@ -317,6 +317,7 @@ public:
      * @param other the Envelope to merge with
      */
     void expandToInclude(const Envelope* other);
+    void expandToInclude(const Envelope& other);
 
     /** \brief
      * Tests if the Envelope `other` lies wholly inside this Envelope
diff --git a/include/geos/index/strtree/SimpleSTRnode.h b/include/geos/index/strtree/SimpleSTRnode.h
new file mode 100644
index 0000000..45c1ad8
--- /dev/null
+++ b/include/geos/index/strtree/SimpleSTRnode.h
@@ -0,0 +1,129 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2020 Paul Ramsey
+ *
+ * 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.
+ *
+ **********************************************************************/
+
+#pragma once
+
+#include <cassert>
+#include <cstddef>
+#include <geos/export.h>
+#include <geos/geom/Envelope.h>
+
+#include <vector>
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
+#endif
+
+namespace geos {
+namespace index { // geos::index
+namespace strtree { // geos::index::strtree
+
+/** \brief
+ * A node of the STR tree.
+ *
+ */
+class GEOS_DLL SimpleSTRnode {
+
+private:
+
+    void *item;
+    std::vector<SimpleSTRnode*> childNodes;
+    geom::Envelope bounds;
+    std::size_t level;
+
+    void computeBounds();
+
+public:
+
+    /*
+     * Constructs an AbstractNode at the given level in the tree
+     */
+    SimpleSTRnode(std::size_t newLevel, const geom::Envelope *itemEnv, void* item, size_t capacity = 10)
+        : level(newLevel)
+        , bounds()
+        , item(item)
+    {
+        childNodes.reserve(capacity);
+        if (itemEnv) {
+            bounds = *itemEnv;
+        }
+
+    }
+
+    SimpleSTRnode(std::size_t newLevel)
+        : SimpleSTRnode(newLevel, nullptr, nullptr)
+    {}
+
+    void toString(std::ostream& os, int level) const;
+
+    const std::vector<SimpleSTRnode*>&
+    getChildNodes() const
+    {
+        return childNodes;
+    }
+
+    void* getItem() const {
+        return item;
+    }
+
+    /**
+     * Returns a representation of space that encloses this Node
+     */
+    const geom::Envelope& getBounds() {
+        if(bounds.isNull()) {
+            computeBounds();
+        }
+        return bounds;
+    }
+
+    /**
+    * Returns 0 if this node is a leaf, 1 if a parent of a leaf, and so on; the
+    * root node will have the highest level
+    */
+    std::size_t getLevel() const {
+        return level;
+    }
+
+    std::size_t size() const {
+        return childNodes.size();
+    }
+
+    /**
+     * Adds either an AbstractNode, or if this is a leaf node, a data object
+     * (wrapped in an ItemBoundable)
+     */
+    void addChildNode(SimpleSTRnode* childNode)
+    {
+        assert(bounds.isNull());
+        childNodes.push_back(childNode);
+    }
+
+    bool isLeaf() const
+    {
+        return item != nullptr;
+    }
+
+
+};
+
+
+} // namespace geos::index::strtree
+} // namespace geos::index
+} // namespace geos
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
diff --git a/include/geos/index/strtree/SimpleSTRtree.h b/include/geos/index/strtree/SimpleSTRtree.h
new file mode 100644
index 0000000..82c2ef6
--- /dev/null
+++ b/include/geos/index/strtree/SimpleSTRtree.h
@@ -0,0 +1,155 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2020 Paul Ramsey
+ *
+ * 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.
+ *
+ **********************************************************************/
+
+#pragma once
+
+#include <geos/export.h>
+#include <geos/index/SpatialIndex.h> // for inheritance
+#include <geos/geom/Envelope.h>
+#include <geos/index/strtree/SimpleSTRnode.h>
+
+#include <vector>
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
+#endif
+
+
+// Forward declarations
+namespace geos {
+namespace geom {
+class Geometry;
+class Envelope;
+}
+}
+
+
+
+namespace geos {
+namespace index { // geos::index
+namespace strtree { // geos::index::strtree
+
+/**
+ * \brief
+ * A query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm.
+ * For two-dimensional spatial data.
+ *
+ * The STR packed R-tree is simple to implement and maximizes space
+ * utilization; that is, as many leaves as possible are filled to capacity.
+ * Overlap between nodes is far less than in a basic R-tree. However, once the
+ * tree has been built (explicitly or on the first call to query), items may
+ * not be added or removed.
+ *
+ * Described in: P. Rigaux, Michel Scholl and Agnes Voisard. Spatial
+ * Databases With Application To GIS. Morgan Kaufmann, San Francisco, 2002.
+ *
+ */
+class GEOS_DLL SimpleSTRtree: public SpatialIndex {
+
+
+private:
+
+    /* Members */
+    std::deque<SimpleSTRnode> storedNodes;
+    std::vector<SimpleSTRnode*> nodes;
+    std::size_t nodeCapacity;
+    SimpleSTRnode* root;
+    bool built;
+
+    /*
+    * Allocate node in storedNodes std::deque for memory locality,
+    * return reference to node.
+    */
+    SimpleSTRnode* createNode(int newLevel, const geom::Envelope* itemEnv, void* item);
+    SimpleSTRnode* createNode(int newLevel);
+
+
+    void build();
+
+    static void sortNodesY(std::vector<SimpleSTRnode*>& nodeList);
+    static void sortNodesX(std::vector<SimpleSTRnode*>& nodeList);
+
+    void query(const geom::Envelope* searchEnv, const SimpleSTRnode* node, ItemVisitor& visitor);
+    void query(const geom::Envelope* searchEnv, const SimpleSTRnode* node, std::vector<void*>& matches);
+
+    /* Turn off copy constructors for MSVC */
+    SimpleSTRtree(const SimpleSTRtree&) = delete;
+    SimpleSTRtree& operator=(const SimpleSTRtree&) = delete;
+
+    std::vector<SimpleSTRnode*> createHigherLevels(
+        std::vector<SimpleSTRnode*>& nodesOfALevel, int level);
+
+    void addParentNodesFromVerticalSlice(
+        std::vector<SimpleSTRnode*>& verticalSlice,
+        int newLevel,
+        std::vector<SimpleSTRnode*>& parentNodes);
+
+    std::vector<SimpleSTRnode*> createParentNodes(
+        std::vector<SimpleSTRnode*>& childNodes,
+        int newLevel);
+
+
+public:
+
+    /**
+     * Constructs an STRtree with the given maximum number of child nodes that
+     * a node may have
+     */
+    SimpleSTRtree(std::size_t capacity = 10)
+        : nodeCapacity(capacity)
+        , built(false)
+        , root(nullptr)
+        {};
+
+    std::size_t getNodeCapacity() const {
+        return nodeCapacity;
+    }
+
+    std::size_t getNumLeafNodes() const {
+        return nodes.size();
+    }
+
+    bool getBuilt() const {
+        return built;
+    }
+
+    SimpleSTRnode* getRoot() const {
+        return root;
+    }
+
+    void insert(geom::Geometry* geom);
+
+    void insert(const geom::Envelope* itemEnv, void* item) override;
+
+    void query(const geom::Envelope* searchEnv, std::vector<void*>& matches) override;
+
+    void query(const geom::Envelope* searchEnv, ItemVisitor& visitor) override;
+
+    bool remove(const geom::Envelope* itemEnv, void* item) override;
+
+    friend std::ostream& operator<<(std::ostream& os, const SimpleSTRtree& tree);
+
+
+};
+
+} // namespace geos::index::strtree
+} // namespace geos::index
+} // namespace geos
+
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
diff --git a/src/geom/Envelope.cpp b/src/geom/Envelope.cpp
index 8624741..cdddcdd 100644
--- a/src/geom/Envelope.cpp
+++ b/src/geom/Envelope.cpp
@@ -173,6 +173,12 @@ Envelope::expandToInclude(const Envelope* other)
     }
 }
 
+void
+Envelope::expandToInclude(const Envelope& other)
+{
+    return expandToInclude(&other);
+}
+
 /*public*/
 bool
 Envelope::covers(double x, double y) const
diff --git a/src/index/strtree/SimpleSTRnode.cpp b/src/index/strtree/SimpleSTRnode.cpp
new file mode 100644
index 0000000..6f3671c
--- /dev/null
+++ b/src/index/strtree/SimpleSTRnode.cpp
@@ -0,0 +1,58 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2006 Refractions Research Inc.
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: index/strtree/STRtree.java rev. 1.11
+ *
+ **********************************************************************/
+
+#include <geos/index/strtree/SimpleSTRnode.h>
+#include <geos/geom/Envelope.h>
+
+
+using namespace geos::geom;
+
+namespace geos {
+namespace index { // geos.index
+namespace strtree { // geos.index.strtree
+
+
+void
+SimpleSTRnode::computeBounds()
+{
+    for (auto* node: childNodes) {
+        bounds.expandToInclude(node->getBounds());
+    }
+}
+
+
+/*public*/
+void
+SimpleSTRnode::toString(std::ostream& os, int level) const
+{
+    for (int i = 0; i < level; i++) {
+        os << "  ";
+    }
+    os << bounds << std::endl;
+    for (auto* node: childNodes) {
+        node->toString(os, level+1);
+    }
+}
+
+
+} // namespace geos.index.strtree
+} // namespace geos.index
+} // namespace geos
+
+
diff --git a/src/index/strtree/SimpleSTRtree.cpp b/src/index/strtree/SimpleSTRtree.cpp
new file mode 100644
index 0000000..8f800a8
--- /dev/null
+++ b/src/index/strtree/SimpleSTRtree.cpp
@@ -0,0 +1,296 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2006 Refractions Research Inc.
+ * Copyright (C) 2001-2002 Vivid Solutions Inc.
+ *
+ * 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.
+ *
+ **********************************************************************
+ *
+ * Last port: index/strtree/STRtree.java rev. 1.11
+ *
+ **********************************************************************/
+
+#include <geos/index/strtree/SimpleSTRtree.h>
+#include <geos/index/ItemVisitor.h>
+#include <geos/geom/Envelope.h>
+#include <geos/geom/Geometry.h>
+
+#include <vector>
+#include <cassert>
+#include <cmath>
+#include <algorithm> // std::sort
+#include <iostream> // for debugging
+#include <limits>
+#include <geos/util/GEOSException.h>
+
+using namespace geos::geom;
+
+namespace geos {
+namespace index { // geos.index
+namespace strtree { // geos.index.strtree
+
+/* private */
+SimpleSTRnode*
+SimpleSTRtree::createNode(int newLevel, const geom::Envelope* itemEnv, void* item)
+{
+    storedNodes.emplace_back(newLevel, itemEnv, item, nodeCapacity);
+    SimpleSTRnode* node = &(storedNodes.back());
+    return node;
+}
+
+/* private */
+SimpleSTRnode*
+SimpleSTRtree::createNode(int newLevel)
+{
+    return createNode(newLevel, nullptr, nullptr);
+}
+
+/* public */
+void
+SimpleSTRtree::insert(geom::Geometry* geom)
+{
+    insert(geom->getEnvelopeInternal(), static_cast<void*>(geom));
+}
+
+/* public */
+void
+SimpleSTRtree::insert(const geom::Envelope* itemEnv, void* item)
+{
+    SimpleSTRnode *node = createNode(0, itemEnv, item);
+    nodes.push_back(node);
+}
+
+/* private static */
+void
+SimpleSTRtree::sortNodesY(std::vector<SimpleSTRnode*>& nodeList)
+{
+    struct {
+        bool operator()(SimpleSTRnode* a, SimpleSTRnode* b) const
+        {
+            const geom::Envelope& ea = a->getBounds();
+            const geom::Envelope& eb = b->getBounds();
+            double ya = (ea.getMinY() + ea.getMaxY()) / 2.0;
+            double yb = (eb.getMinY() + eb.getMaxY()) / 2.0;
+            return ya < yb;
+        }
+    } nodeSortByY;
+
+    std::sort(nodeList.begin(), nodeList.end(), nodeSortByY);
+}
+
+/* private static */
+void
+SimpleSTRtree::sortNodesX(std::vector<SimpleSTRnode*>& nodeList)
+{
+    struct {
+        bool operator()(SimpleSTRnode* a, SimpleSTRnode* b) const
+        {
+            const geom::Envelope& ea = a->getBounds();
+            const geom::Envelope& eb = b->getBounds();
+            double xa = (ea.getMinX() + ea.getMaxX()) / 2.0;
+            double xb = (eb.getMinX() + eb.getMaxX()) / 2.0;
+            return xa < xb;
+        }
+    } nodeSortByX;
+
+    std::sort(nodeList.begin(), nodeList.end(), nodeSortByX);
+}
+
+/* private */
+std::vector<SimpleSTRnode*>
+SimpleSTRtree::createParentNodes(
+    std::vector<SimpleSTRnode*>& childNodes,
+    int newLevel)
+{
+    assert(!childNodes.empty());
+
+    std::size_t minLeafCount = (std::size_t)std::ceil((double)childNodes.size() / (double)nodeCapacity);
+    std::size_t sliceCount = (std::size_t)std::ceil(std::sqrt((double)minLeafCount));
+    std::size_t sliceCapacity = (std::size_t)std::ceil(childNodes.size() / (double)sliceCount);
+
+    sortNodesX(childNodes);
+
+    std::size_t i = 0;
+    std::size_t nChildren = childNodes.size();
+    std::vector<SimpleSTRnode*> parentNodes;
+    std::vector<SimpleSTRnode*> verticalSlice(sliceCapacity);
+    for (std::size_t j = 0; j < sliceCount; j++) {
+        verticalSlice.clear();
+        std::size_t nodesAddedToSlice = 0;
+        while(i < nChildren && nodesAddedToSlice < sliceCapacity) {
+            verticalSlice.push_back(childNodes[i++]);
+            ++nodesAddedToSlice;
+        }
+        addParentNodesFromVerticalSlice(verticalSlice, newLevel, parentNodes);
+    }
+    return parentNodes;
+}
+
+/* private */
+void
+SimpleSTRtree::addParentNodesFromVerticalSlice(
+    std::vector<SimpleSTRnode*>& verticalSlice,
+    int newLevel,
+    std::vector<SimpleSTRnode*>& parentNodes)
+{
+    sortNodesY(verticalSlice);
+
+    SimpleSTRnode* parent = nullptr;
+    for (auto* node: verticalSlice) {
+        if (!parent) {
+            parent = createNode(newLevel);
+        }
+        parent->addChildNode(node);
+        if (parent->size() == nodeCapacity) {
+            parentNodes.push_back(parent);
+            parent = nullptr;
+        }
+    }
+    if (parent)
+        parentNodes.push_back(parent);
+
+    return;
+}
+
+/* private */
+std::vector<SimpleSTRnode*>
+SimpleSTRtree::createHigherLevels(
+    std::vector<SimpleSTRnode*>& nodesOfALevel, int level)
+{
+    int nextLevel = level+1;
+    std::vector<SimpleSTRnode*> parentNodes = createParentNodes(nodesOfALevel, nextLevel);
+    if (parentNodes.size() == 1) {
+        return parentNodes;
+    }
+    return createHigherLevels(parentNodes, nextLevel);
+}
+
+/* private */
+void
+SimpleSTRtree::build()
+{
+    if (built) return;
+
+    if (nodes.empty()) {
+        root = createNode(0);
+    }
+    else {
+        std::vector<SimpleSTRnode*> nodeTree = createHigherLevels(nodes, -1);
+        assert(nodeTree.size()==1);
+        root = nodeTree[0];
+    }
+    built = true;
+}
+
+/* public */
+void
+SimpleSTRtree::query(const geom::Envelope* searchEnv, ItemVisitor& visitor)
+{
+    if(!built) {
+        build();
+    }
+
+    if(nodes.empty()) {
+        assert(root == nullptr);
+        return;
+    }
+
+    if(root->getBounds().intersects(searchEnv)) {
+        query(searchEnv, root, visitor);
+    }
+}
+
+/* private */
+void
+SimpleSTRtree::query(const geom::Envelope* searchEnv,
+    const SimpleSTRnode* node, ItemVisitor& visitor)
+{
+    for(auto* childNode: node->getChildNodes()) {
+
+        if(!childNode->getBounds().intersects(searchEnv)) {
+            continue;
+        }
+
+        if (childNode->isLeaf()) {
+            visitor.visitItem(childNode->getItem());
+        } else {
+            query(searchEnv, childNode, visitor);
+        }
+    }
+}
+
+/* public */
+void
+SimpleSTRtree::query(const geom::Envelope* searchEnv, std::vector<void*>& matches)
+{
+    if(!built) {
+        build();
+    }
+
+    if(nodes.empty()) {
+        assert(root == nullptr);
+        return;
+    }
+
+    if(root->getBounds().intersects(searchEnv)) {
+        query(searchEnv, root, matches);
+    }
+}
+
+/* private */
+void
+SimpleSTRtree::query(const geom::Envelope* searchEnv,
+    const SimpleSTRnode* node, std::vector<void*>& matches)
+{
+    assert(node);
+
+    for(auto* childNode: node->getChildNodes()) {
+
+        if(!childNode->getBounds().intersects(searchEnv)) {
+            continue;
+        }
+
+        if (childNode->isLeaf()) {
+            matches.push_back(childNode->getItem());
+        } else {
+            query(searchEnv, childNode, matches);
+        }
+    }
+}
+
+/* public */
+bool
+SimpleSTRtree::remove(const geom::Envelope* itemEnv, void* item)
+{
+    // no implementation of remove() yet!
+    return false;
+}
+
+
+/*public static*/
+std::ostream&
+operator<<(std::ostream& os, const 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())
+        tree.getRoot()->toString(os, 1);
+    return os;
+}
+
+
+
+} // namespace geos.index.strtree
+} // namespace geos.index
+} // namespace geos
diff --git a/tests/unit/index/strtree/SimpleSTRtreeTest.cpp b/tests/unit/index/strtree/SimpleSTRtreeTest.cpp
new file mode 100644
index 0000000..698f5ab
--- /dev/null
+++ b/tests/unit/index/strtree/SimpleSTRtreeTest.cpp
@@ -0,0 +1,52 @@
+#include <tut/tut.hpp>
+// geos
+#include <geos/index/strtree/SimpleSTRtree.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Point.h>
+
+using namespace geos;
+
+namespace tut {
+// dummy data, not used
+struct test_simplestrtree_data {};
+
+using group = test_group<test_simplestrtree_data>;
+using object = group::object;
+group test_simplestrtree_group("geos::index::strtree::SimpleSTRtree");
+
+//
+// Test Cases
+//
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    index::strtree::SimpleSTRtree t(10);
+    std::vector<std::unique_ptr<geom::Geometry>> geoms;
+    const int gridSize = 10;
+
+    auto gf = geom::GeometryFactory::create();
+    for (int i = 0; i < gridSize; ++i) {
+        for (int j = 0; j < gridSize; ++j) {
+            geom::Coordinate c((double)i, (double)j);
+            geom::Point *pt = gf->createPoint(c);
+            geoms.emplace_back(pt);
+            t.insert(pt);
+        }
+    }
+
+    geom::Envelope qe(-0.5, 1.5, -0.5, 1.5);
+    std::vector<void*> matches;
+    t.query(&qe, matches);
+    std::cout << matches.size() << std::endl;
+    ensure(matches.size() == 4);
+
+    // std::cout << t << std::endl;
+}
+
+
+} // namespace tut
+

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

Summary of changes:
 NEWS                                               |   1 +
 include/geos/geom/Envelope.h                       |   1 +
 include/geos/index/strtree/Makefile.am             |   4 +-
 include/geos/index/strtree/SimpleSTRnode.h         | 129 +++++++++
 include/geos/index/strtree/SimpleSTRtree.h         | 155 +++++++++++
 src/geom/Envelope.cpp                              |   6 +
 src/index/strtree/Makefile.am                      |   4 +-
 .../SimpleSTRnode.cpp}                             |  36 ++-
 src/index/strtree/SimpleSTRtree.cpp                | 296 +++++++++++++++++++++
 tests/unit/Makefile.am                             |   1 +
 tests/unit/index/strtree/SimpleSTRtreeTest.cpp     |  52 ++++
 11 files changed, 674 insertions(+), 11 deletions(-)
 create mode 100644 include/geos/index/strtree/SimpleSTRnode.h
 create mode 100644 include/geos/index/strtree/SimpleSTRtree.h
 copy src/index/{chain/MonotoneChainSelectAction.cpp => strtree/SimpleSTRnode.cpp} (56%)
 create mode 100644 src/index/strtree/SimpleSTRtree.cpp
 create mode 100644 tests/unit/index/strtree/SimpleSTRtreeTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list