GEOS 3.6.2
index/quadtree/Node.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/quadtree/Node.java rev 1.8 (JTS-1.10)
16 *
17 **********************************************************************/
18
19#ifndef GEOS_IDX_QUADTREE_NODE_H
20#define GEOS_IDX_QUADTREE_NODE_H
21
22#include <geos/export.h>
23#include <geos/index/quadtree/NodeBase.h> // for inheritance
24#include <geos/geom/Coordinate.h> // for composition
25#include <geos/geom/Envelope.h> // for inline
26
27#include <string>
28#include <memory>
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 {
37 namespace geom {
38 //class Coordinate;
39 class Envelope;
40 }
41}
42
43namespace geos {
44namespace index { // geos::index
45namespace quadtree { // geos::index::quadtree
46
55class GEOS_DLL Node: public NodeBase {
56
57private:
58
60 std::auto_ptr<geom::Envelope> env;
61
62 geom::Coordinate centre;
63
64 int level;
65
72 Node* getSubnode(int index);
73
74 std::auto_ptr<Node> createSubnode(int index);
75
76protected:
77
78 bool isSearchMatch(const geom::Envelope& searchEnv) const {
79 return env->intersects(searchEnv);
80 }
81
82public:
83
84 // Create a node computing level from given envelope
85 static std::auto_ptr<Node> createNode(const geom::Envelope& env);
86
88 //
92 static std::auto_ptr<Node> createExpanded(std::auto_ptr<Node> node,
93 const geom::Envelope& addEnv);
94
95 Node(std::auto_ptr<geom::Envelope> nenv, int nlevel)
96 :
97 env(nenv),
98 centre((env->getMinX()+env->getMaxX())/2,
99 (env->getMinY()+env->getMaxY())/2),
100 level(nlevel)
101 {
102 }
103
104 virtual ~Node() {}
105
108 geom::Envelope* getEnvelope() { return env.get(); }
109
115 Node* getNode(const geom::Envelope *searchEnv);
116
121 NodeBase* find(const geom::Envelope *searchEnv);
122
123 void insertNode(std::auto_ptr<Node> node);
124
125 std::string toString() const;
126
127};
128
129} // namespace geos::index::quadtree
130} // namespace geos::index
131} // namespace geos
132
133#ifdef _MSC_VER
134#pragma warning(pop)
135#endif
136
137#endif // GEOS_IDX_QUADTREE_NODE_H
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:53
Represents a node of a Quadtree.
Definition index/quadtree/Node.h:55
NodeBase * find(const geom::Envelope *searchEnv)
Returns the smallest existing node containing the envelope.
static std::auto_ptr< Node > createExpanded(std::auto_ptr< Node > node, const geom::Envelope &addEnv)
Create a node containing the given node and envelope.
Node * getNode(const geom::Envelope *searchEnv)
Returns the subquad containing the envelope. Creates the subquad if it does not already exist.
geom::Envelope * getEnvelope()
Definition index/quadtree/Node.h:108
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Contains classes that implement a Quadtree spatial index.
Definition DoubleBits.h:29
Provides classes for various kinds of spatial indexes.
Definition IndexedNestedRingTester.h:31
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25