GEOS 3.11.2
NodedSegmentString.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
8 * Copyright (C) 2006 Refractions Research Inc.
9 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 *
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
15 *
16 *
17 **********************************************************************
18 *
19 * Last port: noding/NodedSegmentString.java r320 (JTS-1.12)
20 *
21 **********************************************************************/
22
23#pragma once
24
25#include <geos/export.h>
26#include <geos/algorithm/LineIntersector.h>
27#include <geos/geom/Coordinate.h>
28#include <geos/geom/CoordinateSequence.h> // for inlines
29#include <geos/noding/NodedSegmentString.h>
30#include <geos/noding/NodableSegmentString.h> // for inheritance
31#include <geos/noding/Octant.h>
32#include <geos/noding/SegmentNode.h>
33#include <geos/noding/SegmentNodeList.h>
34#include <geos/noding/SegmentString.h>
35#include <geos/util/IllegalArgumentException.h>
36
37#include <cstddef>
38
39#ifdef _MSC_VER
40#pragma warning(push)
41#pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list
42#endif
43
44namespace geos {
45namespace noding { // geos::noding
46
60public:
61
62 // TODO: provide a templated method using an output iterator
63 template <class II>
64 static void
65 getNodedSubstrings(II from, II too_far,
66 SegmentString::NonConstVect* resultEdgelist)
67 {
68 for(II i = from; i != too_far; ++i) {
69 NodedSegmentString* nss = dynamic_cast<NodedSegmentString*>(*i);
70 assert(nss);
71 nss->getNodeList().addSplitEdges(resultEdgelist);
72 }
73 }
74
75 template <class C>
76 static void
77 getNodedSubstrings(C* segStrings,
78 SegmentString::NonConstVect* resultEdgelist)
79 {
80 getNodedSubstrings(segStrings->begin(), segStrings->end(), resultEdgelist);
81 }
82
83 static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings,
84 SegmentString::NonConstVect* resultEdgeList);
85
87 static SegmentString::NonConstVect* getNodedSubstrings(
88 const SegmentString::NonConstVect& segStrings);
89
90 std::vector<geom::Coordinate> getNodedCoordinates();
91
92 bool hasNodes() const
93 {
94 return nodeList.size() > 0;
95 }
96
106 NodedSegmentString(geom::CoordinateSequence* newPts, const void* newContext)
107 : NodableSegmentString(newContext)
108 , nodeList(this)
109 , pts(newPts)
110 {}
111
113 : NodableSegmentString(ss->getData())
114 , nodeList(this)
115 , pts(ss->getCoordinates()->clone())
116 {}
117
118 ~NodedSegmentString() override = default;
119
120 SegmentNodeList& getNodeList();
121
122 const SegmentNodeList& getNodeList() const;
123
124 size_t
125 size() const override
126 {
127 return pts->size();
128 }
129
130 const geom::Coordinate& getCoordinate(std::size_t i) const override;
131
133 geom::CoordinateSequence* releaseCoordinates();
134
135 bool isClosed() const override;
136
137 std::ostream& print(std::ostream& os) const override;
138
139
147 int getSegmentOctant(std::size_t index) const
148 {
149 if (index >= size() - 1) {
150 return -1;
151 }
152 return safeOctant(getCoordinate(index), getCoordinate(index + 1));
153 //return Octant::octant(getCoordinate(index), getCoordinate(index+1));
154 };
155
162 std::size_t segmentIndex, std::size_t geomIndex)
163 {
164 for (std::size_t i = 0, n = li->getIntersectionNum(); i < n; ++i) {
165 addIntersection(li, segmentIndex, geomIndex, i);
166 }
167 };
168
177 std::size_t segmentIndex,
178 std::size_t geomIndex, std::size_t intIndex)
179 {
180 ::geos::ignore_unused_variable_warning(geomIndex);
181
182 const geom::Coordinate& intPt = li->getIntersection(intIndex);
183 addIntersection(intPt, segmentIndex);
184 };
185
194 std::size_t segmentIndex)
195 {
196 std::size_t normalizedSegmentIndex = segmentIndex;
197
198 if (segmentIndex > size() - 2) {
199 throw util::IllegalArgumentException("SegmentString::addIntersection: SegmentIndex out of range");
200 }
201
202 // normalize the intersection point location
203 auto nextSegIndex = normalizedSegmentIndex + 1;
204 if (nextSegIndex < size()) {
205 const geom::Coordinate& nextPt = pts->getAt(nextSegIndex);
206
207 // Normalize segment index if intPt falls on vertex
208 // The check for point equality is 2D only -
209 // Z values are ignored
210 if(intPt.equals2D(nextPt)) {
211 normalizedSegmentIndex = nextSegIndex;
212 }
213 }
214
215 /*
216 * Add the intersection point to edge intersection list
217 * (unless the node is already known)
218 */
219 nodeList.add(intPt, normalizedSegmentIndex);
220 };
221
222private:
223
224 SegmentNodeList nodeList;
225
226 std::unique_ptr<geom::CoordinateSequence> pts;
227
228 static int safeOctant(const geom::Coordinate& p0, const geom::Coordinate& p1)
229 {
230 if(p0.equals2D(p1)) {
231 return 0;
232 }
233 return Octant::octant(p0, p1);
234 };
235
236};
237
238} // namespace geos::noding
239} // namespace geos
240
241#ifdef _MSC_VER
242#pragma warning(pop)
243#endif
244
245
246
247
248
249
250
251
252
253
254
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:50
const geom::Coordinate & getIntersection(std::size_t intIndex) const
Definition: LineIntersector.h:211
size_t getIntersectionNum() const
Definition: LineIntersector.h:198
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An interface for classes which support adding nodes to a segment string.
Definition: NodableSegmentString.h:36
Represents a list of contiguous line segments, and supports noding the segments.
Definition: NodedSegmentString.h:59
static SegmentString::NonConstVect * getNodedSubstrings(const SegmentString::NonConstVect &segStrings)
Returns allocated object.
void addIntersection(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex, std::size_t intIndex)
Add an SegmentNode for intersection intIndex.
Definition: NodedSegmentString.h:176
NodedSegmentString(geom::CoordinateSequence *newPts, const void *newContext)
Creates a new segment string from a list of vertices.
Definition: NodedSegmentString.h:106
void addIntersections(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex)
Add SegmentNodes for one or both intersections found for a segment of an edge to the edge intersectio...
Definition: NodedSegmentString.h:161
void addIntersection(const geom::Coordinate &intPt, std::size_t segmentIndex)
Add an SegmentNode for intersection intIndex.
Definition: NodedSegmentString.h:193
geom::CoordinateSequence * getCoordinates() const override
Return a pointer to the CoordinateSequence associated with this SegmentString.
int getSegmentOctant(std::size_t index) const
Gets the octant of the segment starting at vertex index.
Definition: NodedSegmentString.h:147
A list of the SegmentNode present along a NodedSegmentString.
Definition: SegmentNodeList.h:54
void addSplitEdges(std::vector< SegmentString * > &edgeList)
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:45
Indicates one or more illegal arguments.
Definition: IllegalArgumentException.h:33
Basic namespace for all GEOS functionalities.
Definition: geos.h:39