GEOS 3.14.0dev
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 {
33 class CoordinateSequence;
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
51class GEOS_DLL RelateGeometry {
52 using Coordinate = geos::geom::Coordinate;
53 using CoordinateSequence = geos::geom::CoordinateSequence;
54 using Dimension = geos::geom::Dimension;
55 using Envelope = geos::geom::Envelope;
56 using Geometry = geos::geom::Geometry;
58 using CoordinateXY = geos::geom::CoordinateXY;
59 using LinearRing = geos::geom::LinearRing;
60 using LineString = geos::geom::LineString;
61 using MultiPolygon = geos::geom::MultiPolygon;
62 using Point = geos::geom::Point;
63 using BoundaryNodeRule = geos::algorithm::BoundaryNodeRule;
64 using SegmentString = geos::noding::SegmentString;
65
66private:
67
68 // Members
69
70 const Geometry* geom;
71 bool m_isPrepared = false;
72 const Envelope* geomEnv;
73 const BoundaryNodeRule& boundaryNodeRule;
74 int geomDim = Dimension::False;
75 bool isLineZeroLen = false;
76 bool isGeomEmpty = false;
77
78 Coordinate::ConstXYSet uniquePoints;
79 std::unique_ptr<RelatePointLocator> locator;
80 int elementId = 0;
81 bool hasPoints = false;
82 bool hasLines = false;
83 bool hasAreas = false;
84
85 /*
86 * Memory contexts for lower level allocations
87 */
88 std::vector<std::unique_ptr<const RelateSegmentString>> segStringTempStore;
89 std::vector<std::unique_ptr<const RelateSegmentString>> segStringPermStore;
90 std::vector<std::unique_ptr<CoordinateSequence>> csStore;
91
92
93 // Methods
94
95 void analyzeDimensions();
96
104 static bool isZeroLength(const Geometry* geom);
105
106 static bool isZeroLength(const LineString* line);
107
108 bool isZeroLengthLine(const Geometry* g) const {
109 // avoid expensive zero-length calculation if not linear
110 if (getDimension() != Dimension::L)
111 return false;
112 return isZeroLength(g);
113 };
114
115 RelatePointLocator* getLocator();
116
117 Coordinate::ConstXYSet createUniquePoints();
118
119 void extractSegmentStringsFromAtomic(bool isA,
120 const Geometry* geom, const MultiPolygon* parentPolygonal,
121 const Envelope* env,
122 std::vector<const SegmentString*>& segStrings,
123 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
124
125 void extractRingToSegmentString(bool isA,
126 const LinearRing* ring, int ringId, const Envelope* env,
127 const Geometry* parentPoly,
128 std::vector<const SegmentString*>& segStrings,
129 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
130
131 void extractSegmentStrings(bool isA,
132 const Envelope* env, const Geometry* geom,
133 std::vector<const SegmentString*>& segStrings,
134 std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
135
136 const CoordinateSequence* orientAndRemoveRepeated(
137 const CoordinateSequence* cs, bool orientCW);
138
139 const CoordinateSequence* removeRepeated(
140 const CoordinateSequence* cs);
141
142public:
143
144 static constexpr bool GEOM_A = true;
145 static constexpr bool GEOM_B = false;
146
147 RelateGeometry(const Geometry* input)
148 : RelateGeometry(input, false, BoundaryNodeRule::getBoundaryRuleMod2())
149 {};
150
151 RelateGeometry(const Geometry* input, const BoundaryNodeRule& bnRule)
152 : RelateGeometry(input, false, bnRule)
153 {};
154
155 RelateGeometry(const Geometry* input, bool p_isPrepared, const BoundaryNodeRule& bnRule);
156
157 static std::string name(bool isA);
158
159 const Geometry* getGeometry() const {
160 return geom;
161 }
162
163 bool isPrepared() const {
164 return m_isPrepared;
165 }
166
167 const Envelope* getEnvelope() const {
168 return geomEnv;
169 }
170
171 inline int getDimension() const {
172 return geomDim;
173 }
174
175 bool hasDimension(int dim) const {
176 switch (dim) {
177 case Dimension::P: return hasPoints;
178 case Dimension::L: return hasLines;
179 case Dimension::A: return hasAreas;
180 }
181 return false;
182 }
183
184 bool hasAreaAndLine() const {
185 return hasAreas && hasLines;
186 }
187
194 int getDimensionReal() const;
195
196 bool hasEdges() const;
197
198 bool isNodeInArea(const CoordinateXY* nodePt, const Geometry* parentPolygonal);
199
200 int locateLineEndWithDim(const CoordinateXY* p);
201
212 Location locateAreaVertex(const CoordinateXY* pt);
213
214 Location locateNode(const CoordinateXY* pt, const Geometry* parentPolygonal);
215
216 int locateWithDim(const CoordinateXY* pt);
217
234 bool isSelfNodingRequired() const;
235
246 bool isPolygonal() const;
247
248 bool isEmpty() const;
249
250 bool hasBoundary();
251
252 Coordinate::ConstXYSet& getUniquePoints();
253
254 std::vector<const Point*> getEffectivePoints();
255
265 std::vector<const SegmentString*> extractSegmentStrings(bool isA, const Envelope* env);
266
267 std::string toString() const;
268
269 friend std::ostream& operator<<(std::ostream& os, const RelateGeometry& rg);
270
276 RelateGeometry(const RelateGeometry&) = delete;
277 RelateGeometry& operator=(const RelateGeometry&) = delete;
278
279};
280
281} // namespace geos.operation.relateng
282} // namespace geos.operation
283} // namespace geos
284
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
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Definition Dimension.h:27
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
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