GEOS 3.13.1
RelateGeometry.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (c) 2024 Martin Davis
7 * Copyright (C) 2024 Paul Ramsey <pramsey@cleverelephant.ca>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************/
15
16#pragma once
17
18#include <geos/algorithm/BoundaryNodeRule.h>
19#include <geos/geom/Coordinate.h>
20#include <geos/geom/Dimension.h>
21#include <geos/geom/Location.h>
22#include <geos/operation/relateng/RelatePointLocator.h>
23#include <geos/operation/relateng/RelateSegmentString.h>
24#include <geos/export.h>
25
26#include <string>
27#include <sstream>
28
29
30// Forward declarations
31namespace geos {
32namespace geom {
34 class Envelope;
35 class Geometry;
36 class LinearRing;
37 class LineString;
38 class MultiPolygon;
39 class Point;
40}
41namespace noding {
42 class SegmentString;
43}
44}
45
46
47namespace geos { // geos.
48namespace operation { // geos.operation
49namespace relateng { // geos.operation.relateng
50
51using namespace geos::geom;
54
55
56class GEOS_DLL RelateGeometry {
57
58private:
59
60 // Members
61
62 const Geometry* geom;
63 bool m_isPrepared = false;
64 const Envelope* geomEnv;
65 const BoundaryNodeRule& boundaryNodeRule;
66 int geomDim = Dimension::False;
67 bool isLineZeroLen = false;
68 bool isGeomEmpty = false;
69
70 Coordinate::ConstXYSet uniquePoints;
71 std::unique_ptr<RelatePointLocator> locator;
72 int elementId = 0;
73 bool hasPoints = false;
74 bool hasLines = false;
75 bool hasAreas = false;
76
77 /*
78 * Memory contexts for lower level allocations
79 */
80 std::vector<std::unique_ptr<const RelateSegmentString>> segStringTempStore;
81 std::vector<std::unique_ptr<const RelateSegmentString>> segStringPermStore;
82 std::vector<std::unique_ptr<CoordinateSequence>> csStore;
83
84
85 // Methods
86
87 void analyzeDimensions();
88
96 static bool isZeroLength(const Geometry* geom);
97
98 static bool isZeroLength(const LineString* line);
99
100 bool isZeroLengthLine(const Geometry* g) const {
101 // avoid expensive zero-length calculation if not linear
102 if (getDimension() != Dimension::L)
103 return false;
104 return isZeroLength(g);
105 };
106
107 RelatePointLocator* getLocator();
108
109 Coordinate::ConstXYSet createUniquePoints();
110
111 void extractSegmentStringsFromAtomic(bool isA,
112 const Geometry* geom, const MultiPolygon* parentPolygonal,
113 const Envelope* env,
114 std::vector<const SegmentString*>& segStrings,
115 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
116
117 void extractRingToSegmentString(bool isA,
118 const LinearRing* ring, int ringId, const Envelope* env,
119 const Geometry* parentPoly,
120 std::vector<const SegmentString*>& segStrings,
121 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
122
123 void extractSegmentStrings(bool isA,
124 const Envelope* env, const Geometry* geom,
125 std::vector<const SegmentString*>& segStrings,
126 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
127
128 const CoordinateSequence* orientAndRemoveRepeated(
129 const CoordinateSequence* cs, bool orientCW);
130
131 const CoordinateSequence* removeRepeated(
132 const CoordinateSequence* cs);
133
134public:
135
136 static constexpr bool GEOM_A = true;
137 static constexpr bool GEOM_B = false;
138
139 RelateGeometry(const Geometry* input)
140 : RelateGeometry(input, false, BoundaryNodeRule::getBoundaryRuleMod2())
141 {};
142
143 RelateGeometry(const Geometry* input, const BoundaryNodeRule& bnRule)
144 : RelateGeometry(input, false, bnRule)
145 {};
146
147 RelateGeometry(const Geometry* input, bool p_isPrepared, const BoundaryNodeRule& bnRule);
148
149 static std::string name(bool isA);
150
151 const Geometry* getGeometry() const {
152 return geom;
153 }
154
155 bool isPrepared() const {
156 return m_isPrepared;
157 }
158
159 const Envelope* getEnvelope() const {
160 return geomEnv;
161 }
162
163 inline int getDimension() const {
164 return geomDim;
165 }
166
167 bool hasDimension(int dim) const {
168 switch (dim) {
169 case Dimension::P: return hasPoints;
170 case Dimension::L: return hasLines;
171 case Dimension::A: return hasAreas;
172 }
173 return false;
174 }
175
176 bool hasAreaAndLine() const {
177 return hasAreas && hasLines;
178 }
179
186 int getDimensionReal() const;
187
188 bool hasEdges() const;
189
190 bool isNodeInArea(const CoordinateXY* nodePt, const Geometry* parentPolygonal);
191
192 int locateLineEndWithDim(const CoordinateXY* p);
193
204 Location locateAreaVertex(const CoordinateXY* pt);
205
206 Location locateNode(const CoordinateXY* pt, const Geometry* parentPolygonal);
207
208 int locateWithDim(const CoordinateXY* pt);
209
226 bool isSelfNodingRequired() const;
227
238 bool isPolygonal() const;
239
240 bool isEmpty() const;
241
242 bool hasBoundary();
243
244 Coordinate::ConstXYSet& getUniquePoints();
245
246 std::vector<const Point*> getEffectivePoints();
247
257 std::vector<const SegmentString*> extractSegmentStrings(bool isA, const Envelope* env);
258
259 std::string toString() const;
260
261 friend std::ostream& operator<<(std::ostream& os, const RelateGeometry& rg);
262
268 RelateGeometry(const RelateGeometry&) = delete;
269 RelateGeometry& operator=(const RelateGeometry&) = delete;
270
271};
272
273} // namespace geos.operation.relateng
274} // namespace geos.operation
275} // namespace geos
276
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition BoundaryNodeRule.h:52
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Definition MultiPolygon.h:58
Definition Point.h:61
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
Definition Angle.h:26
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:39