File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/XS/libgeos.x/i/geos/index/quadtree/Quadtree.h
Criterion Covered Total %
statement 3 3 100.0
branch 1 2 50.0
condition n/a
subroutine n/a
pod n/a
total 4 5 80.0


line stmt bran cond sub pod time code
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/quadtree/Quadtree.java rev. 1.16 (JTS-1.10)
16             *
17             **********************************************************************/
18              
19             #ifndef GEOS_IDX_QUADTREE_QUADTREE_H
20             #define GEOS_IDX_QUADTREE_QUADTREE_H
21              
22             #include
23             #include // for inheritance
24             #include // for composition
25              
26             #include
27             #include
28              
29             #ifdef _MSC_VER
30             #pragma warning(push)
31             #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32             #endif
33              
34             // Forward declarations
35             namespace geos {
36             namespace geom {
37             class Envelope;
38             }
39             namespace index {
40             namespace quadtree {
41             // class Root;
42             }
43             }
44             }
45              
46             namespace geos {
47             namespace index { // geos::index
48             namespace quadtree { // geos::index::quadtree
49              
50             /**
51             * \brief
52             * A Quadtree is a spatial index structure for efficient querying
53             * of 2D rectangles. If other kinds of spatial objects
54             * need to be indexed they can be represented by their
55             * envelopes
56             *
57             * The quadtree structure is used to provide a primary filter
58             * for range rectangle queries. The query() method returns a list of
59             * all objects which may intersect the query rectangle. Note that
60             * it may return objects which do not in fact intersect.
61             * A secondary filter is required to test for exact intersection.
62             * Of course, this secondary filter may consist of other tests besides
63             * intersection, such as testing other kinds of spatial relationships.
64             *
65             * This implementation does not require specifying the extent of the inserted
66             * items beforehand. It will automatically expand to accomodate any extent
67             * of dataset.
68             *
69             * This data structure is also known as an MX-CIF quadtree
70             * following the usage of Samet and others.
71             */
72             class GEOS_DLL Quadtree: public SpatialIndex {
73              
74             private:
75              
76             std::vector newEnvelopes;
77              
78             void collectStats(const geom::Envelope& itemEnv);
79              
80             Root root;
81              
82             /**
83             * Statistics
84             *
85             * minExtent is the minimum envelope extent of all items
86             * inserted into the tree so far. It is used as a heuristic value
87             * to construct non-zero envelopes for features with zero X and/or
88             * Y extent.
89             * Start with a non-zero extent, in case the first feature inserted has
90             * a zero extent in both directions. This value may be non-optimal, but
91             * only one feature will be inserted with this value.
92             */
93             double minExtent;
94              
95             public:
96             /**
97             * \brief
98             * Ensure that the envelope for the inserted item has non-zero extents.
99             *
100             * Use the current minExtent to pad the envelope, if necessary.
101             * Can return a new Envelope or the given one (casted to non-const).
102             */
103             static geom::Envelope* ensureExtent(const geom::Envelope *itemEnv,
104             double minExtent);
105              
106             /**
107             * \brief
108             * Constructs a Quadtree with zero items.
109             */
110 6           Quadtree()
111             :
112             root(),
113 6 50         minExtent(1.0)
114 6           {}
115              
116             ~Quadtree() override;
117              
118             /// Returns the number of levels in the tree.
119             int depth();
120              
121             /// Returns the number of items in the tree.
122             int size();
123              
124             void insert(const geom::Envelope *itemEnv, void *item) override;
125              
126             /** \brief
127             * Queries the tree and returns items which may lie
128             * in the given search envelope.
129             *
130             * Precisely, the items that are returned are all items in the tree
131             * whose envelope may intersect the search Envelope.
132             * Note that some items with non-intersecting envelopes may be
133             * returned as well;
134             * the client is responsible for filtering these out.
135             * In most situations there will be many items in the tree which do not
136             * intersect the search envelope and which are not returned - thus
137             * providing improved performance over a simple linear scan.
138             *
139             * @param searchEnv the envelope of the desired query area.
140             * @param ret a vector where items which may intersect the
141             * search envelope are pushed
142             */
143             void query(const geom::Envelope *searchEnv, std::vector& ret) override;
144              
145              
146             /** \brief
147             * Queries the tree and visits items which may lie in
148             * the given search envelope.
149             *
150             * Precisely, the items that are visited are all items in the tree
151             * whose envelope may intersect the search Envelope.
152             * Note that some items with non-intersecting envelopes may be
153             * visited as well;
154             * the client is responsible for filtering these out.
155             * In most situations there will be many items in the tree which do not
156             * intersect the search envelope and which are not visited - thus
157             * providing improved performance over a simple linear scan.
158             *
159             * @param searchEnv the envelope of the desired query area.
160             * @param visitor a visitor object which is passed the visited items
161             */
162             void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) override
163             {
164             /*
165             * the items that are matched are the items in quads which
166             * overlap the search envelope
167             */
168             root.visit(searchEnv, visitor);
169             }
170              
171             /**
172             * Removes a single item from the tree.
173             *
174             * @param itemEnv the Envelope of the item to be removed
175             * @param item the item to remove
176             * @return true if the item was found (and thus removed)
177             */
178             bool remove(const geom::Envelope* itemEnv, void* item) override;
179              
180             /// Return a list of all items in the Quadtree
181             std::vector* queryAll();
182              
183             std::string toString() const;
184              
185             };
186              
187             } // namespace geos::index::quadtree
188             } // namespace geos::index
189             } // namespace geos
190              
191             #ifdef _MSC_VER
192             #pragma warning(pop)
193             #endif
194              
195             #endif // GEOS_IDX_QUADTREE_QUADTREE_H