GEOS 3.11.1
STRtree.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: index/strtree/STRtree.java rev. 1.11
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22#include <geos/index/strtree/ItemDistance.h>
23#include <geos/index/strtree/BoundablePair.h>
24#include <geos/index/strtree/AbstractSTRtree.h> // for inheritance
25#include <geos/index/SpatialIndex.h> // for inheritance
26#include <geos/geom/Envelope.h> // for inlines
27
28#include <vector>
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33#endif
34
35// Forward declarations
36namespace geos {
37namespace index {
38namespace strtree {
39class Boundable;
40}
41}
42}
43
44namespace geos {
45namespace index { // geos::index
46namespace strtree { // geos::index::strtree
47
63class GEOS_DLL STRtree: public AbstractSTRtree, public SpatialIndex {
66
67private:
68 class GEOS_DLL STRIntersectsOp: public AbstractSTRtree::IntersectsOp {
69 public:
70 bool intersects(const void* aBounds, const void* bBounds) override;
71 };
72
80 std::unique_ptr<BoundableList> createParentBoundables(BoundableList* childBoundables, int newLevel) override;
81
82 std::unique_ptr<BoundableList> createParentBoundablesFromVerticalSlices(std::vector<BoundableList*>* verticalSlices,
83 int newLevel);
84
85 STRIntersectsOp intersectsOp;
86
87 std::unique_ptr<BoundableList> sortBoundablesY(const BoundableList* input);
88 std::unique_ptr<BoundableList> sortBoundablesX(const BoundableList* input);
89
90 std::unique_ptr<BoundableList> createParentBoundablesFromVerticalSlice(
91 BoundableList* childBoundables,
92 int newLevel);
93
99 std::vector<BoundableList*>* verticalSlices(
100 BoundableList* childBoundables,
101 std::size_t sliceCount);
102
103 bool isWithinDistance(BoundablePair* initBndPair, double maxDistance);
104
105protected:
106
107 AbstractNode* createNode(int level) override;
108
111 {
112 return &intersectsOp;
113 }
114
115public:
116
117 ~STRtree() override = default;
118
123 STRtree(std::size_t nodeCapacity = 10);
124
125 void insert(const geom::Envelope* itemEnv, void* item) override;
126
127 //static double centreX(const geom::Envelope *e);
128
129 static double
130 avg(double a, double b)
131 {
132 return (a + b) / 2.0;
133 }
134
135 static double
136 centreY(const geom::Envelope* e)
137 {
138 return STRtree::avg(e->getMinY(), e->getMaxY());
139 }
140
141 void
142 query(const geom::Envelope* searchEnv, std::vector<void*>& matches) override
143 {
144 AbstractSTRtree::query(searchEnv, matches);
145 }
146
147 void
148 query(const geom::Envelope* searchEnv, ItemVisitor& visitor) override
149 {
150 return AbstractSTRtree::query(searchEnv, visitor);
151 }
152
153 std::pair<const void*, const void*> nearestNeighbour(ItemDistance* itemDist);
154 const void* nearestNeighbour(const geom::Envelope* env, const void* item, ItemDistance* itemDist);
155 std::pair<const void*, const void*> nearestNeighbour(STRtree* tree, ItemDistance* itemDist);
156 std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair);
157 std::pair<const void*, const void*> nearestNeighbour(BoundablePair* initBndPair, double maxDistance);
158
159 bool
160 remove(const geom::Envelope* itemEnv, void* item) override
161 {
162 return AbstractSTRtree::remove(itemEnv, item);
163 }
164
165 bool isWithinDistance(STRtree* tree, ItemDistance* itemDist, double maxDistance);
166
167};
168
169} // namespace geos::index::strtree
170} // namespace geos::index
171} // namespace geos
172
173
174#ifdef _MSC_VER
175#pragma warning(pop)
176#endif
177
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
double getMaxY() const
Returns the Envelope maximum y-value. min y > max y indicates that this is a null Envelope.
Definition: Envelope.h:295
double getMinY() const
Returns the Envelope minimum y-value. min y > max y indicates that this is a null Envelope.
Definition: Envelope.h:315
A visitor for items in an index.
Definition: ItemVisitor.h:28
Abstract class defines basic insertion and query operations supported by classes implementing spatial...
Definition: SpatialIndex.h:46
A node of the STR tree.
Definition: AbstractNode.h:43
A test for intersection between two bounds, necessary because subclasses of AbstractSTRtree have diff...
Definition: AbstractSTRtree.h:175
Base class for STRtree and SIRtree.
Definition: AbstractSTRtree.h:138
virtual void insert(const void *bounds, void *item)
Also builds the tree, if necessary.
void query(const void *searchBounds, std::vector< void * > &foundItems)
Also builds the tree, if necessary.
A pair of Boundables, whose leaf items support a distance metric between them.
Definition: BoundablePair.h:43
A function method which computes the distance between two ItemBoundables in an STRtree....
Definition: ItemDistance.h:33
A query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm. For two-dimensional spatia...
Definition: STRtree.h:63
STRtree(std::size_t nodeCapacity=10)
void query(const geom::Envelope *searchEnv, ItemVisitor &visitor) override
Queries the index for all items whose extents intersect the given search Envelope and applies an Item...
Definition: STRtree.h:148
IntersectsOp * getIntersectsOp() override
Definition: STRtree.h:110
void insert(const geom::Envelope *itemEnv, void *item) override
Adds a spatial item with an extent specified by the given Envelope to the index.
void query(const geom::Envelope *searchEnv, std::vector< void * > &matches) override
Queries the index for all items whose extents intersect the given search Envelope.
Definition: STRtree.h:142
bool remove(const geom::Envelope *itemEnv, void *item) override
Removes a single item from the tree.
Definition: STRtree.h:160
std::vector< Boundable * > BoundableList
A list of boundables. TODO: use a list.
Definition: AbstractSTRtree.h:43
Basic namespace for all GEOS functionalities.
Definition: geos.h:39