GEOS  3.14.0dev
GeometryGraph.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geomgraph/GeometryGraph.java r428 (JTS-1.12+)
18  *
19  **********************************************************************/
20 
21 
22 #pragma once
23 
24 #include <geos/export.h>
25 #include <map>
26 #include <unordered_map>
27 #include <vector>
28 #include <memory>
29 
30 #include <geos/geom/Coordinate.h>
31 #include <geos/geom/CoordinateSequence.h> // for unique_ptr<CoordinateSequence>
32 #include <geos/geomgraph/PlanarGraph.h>
33 #include <geos/geomgraph/index/SegmentIntersector.h>
34 #include <geos/geom/LineString.h> // for LineStringLT
35 
36 #ifdef _MSC_VER
37 #pragma warning(push)
38 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
39 #endif
40 
41 // Forward declarations
42 namespace geos {
43 namespace geom {
44 class LineString;
45 class LinearRing;
46 class Polygon;
47 class Geometry;
48 class GeometryCollection;
49 class Point;
50 class Envelope;
51 }
52 namespace algorithm {
53 class LineIntersector;
54 class BoundaryNodeRule;
55 }
56 namespace geomgraph {
57 class Edge;
58 class Node;
59 namespace index {
60 class EdgeSetIntersector;
61 }
62 }
63 }
64 
65 namespace geos {
66 namespace geomgraph { // geos.geomgraph
67 
71 class GEOS_DLL GeometryGraph final: public PlanarGraph {
72  using PlanarGraph::add;
74 
75 private:
76 
77  const geom::Geometry* parentGeom;
78 
87  std::unordered_map<const geom::LineString*, Edge*> lineEdgeMap;
88 
93  bool useBoundaryDeterminationRule;
94 
95  const algorithm::BoundaryNodeRule& boundaryNodeRule;
96 
101  uint8_t argIndex;
102 
104  std::unique_ptr< geom::CoordinateSequence > boundaryPoints;
105 
106  std::unique_ptr< std::vector<Node*> > boundaryNodes;
107 
108  bool hasTooFewPointsVar;
109 
110  geom::Coordinate invalidPoint;
111 
113  index::EdgeSetIntersector* createEdgeSetIntersector();
114 
115  void add(const geom::Geometry* g);
116  // throw(UnsupportedOperationException);
117 
118  void addCollection(const geom::GeometryCollection* gc);
119 
120  void addPoint(const geom::Point* p);
121 
122  void addPolygonRing(const geom::LinearRing* lr,
123  geom::Location cwLeft, geom::Location cwRight);
124 
125  void addPolygon(const geom::Polygon* p);
126 
127  void addLineString(const geom::LineString* line);
128 
129  void insertPoint(uint8_t p_argIndex, const geom::Coordinate& coord,
130  geom::Location onLocation);
131 
139  void insertBoundaryPoint(uint8_t p_argIndex, const geom::Coordinate& coord);
140 
141  void addSelfIntersectionNodes(uint8_t p_argIndex);
142 
150  void addSelfIntersectionNode(uint8_t p_argIndex,
151  const geom::Coordinate& coord, geom::Location loc);
152 
153  // Declare type as noncopyable
154  GeometryGraph(const GeometryGraph& other) = delete;
155  GeometryGraph& operator=(const GeometryGraph& rhs) = delete;
156 
157 public:
158 
159  static bool isInBoundary(int boundaryCount);
160 
161  static geom::Location determineBoundary(int boundaryCount);
162 
163  static geom::Location determineBoundary(
164  const algorithm::BoundaryNodeRule& boundaryNodeRule,
165  int boundaryCount);
166 
167  GeometryGraph(uint8_t newArgIndex, const geom::Geometry* newParentGeom);
168 
169  GeometryGraph(uint8_t newArgIndex, const geom::Geometry* newParentGeom,
170  const algorithm::BoundaryNodeRule& boundaryNodeRule);
171 
172  ~GeometryGraph() override {};
173 
174  const geom::Geometry* getGeometry()
175  {
176  return parentGeom;
177  };
178 
180  void getBoundaryNodes(std::vector<Node*>& bdyNodes)
181  {
182  nodes->getBoundaryNodes(static_cast<uint8_t>(argIndex), bdyNodes);
183  };
184 
185  std::vector<Node*>* getBoundaryNodes();
186 
189 
190  Edge* findEdge(const geom::LineString* line) const;
191 
192  void computeSplitEdges(std::vector<Edge*>* edgelist);
193 
194  void addEdge(Edge* e);
195 
196  void addPoint(geom::Coordinate& pt);
197 
212  std::unique_ptr<index::SegmentIntersector>
215  bool computeRingSelfNodes,
216  const geom::Envelope* env = nullptr)
217  {
218  return computeSelfNodes(*li, computeRingSelfNodes, env);
219  }
220 
221  // Quick inline calling the function above, the above should probably
222  // be deprecated.
223  std::unique_ptr<index::SegmentIntersector> computeSelfNodes(
225  bool computeRingSelfNodes, const geom::Envelope* env = nullptr);
226 
227  std::unique_ptr<index::SegmentIntersector> computeEdgeIntersections(GeometryGraph* g,
228  algorithm::LineIntersector* li, bool includeProper,
229  const geom::Envelope* env = nullptr);
230 
231  std::vector<Edge*>* getEdges();
232 
233  bool hasTooFewPoints();
234 
235  const geom::Coordinate& getInvalidPoint();
236 
238  getBoundaryNodeRule() const
239  {
240  return boundaryNodeRule;
241  }
242 
243 };
244 
245 
246 } // namespace geos.geomgraph
247 } // namespace geos
248 
249 #ifdef _MSC_VER
250 #pragma warning(pop)
251 #endif
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition: BoundaryNodeRule.h:52
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:53
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
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:51
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: Point.h:61
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Definition: geomgraph/Edge.h:63
A GeometryGraph is a graph that models a given Geometry.
Definition: GeometryGraph.h:71
void getBoundaryNodes(std::vector< Node * > &bdyNodes)
Returned object is owned by this GeometryGraph.
Definition: GeometryGraph.h:180
geom::CoordinateSequence * getBoundaryPoints()
Returned object is owned by this GeometryGraph.
std::unique_ptr< index::SegmentIntersector > computeSelfNodes(algorithm::LineIntersector *li, bool computeRingSelfNodes, const geom::Envelope *env=nullptr)
Compute self-nodes, taking advantage of the Geometry type to minimize the number of intersection test...
Definition: GeometryGraph.h:213
Represents a directed graph which is embeddable in a planar surface.
Definition: geomgraph/PlanarGraph.h:72
Edge * findEdge(const geom::Coordinate &p0, const geom::Coordinate &p1)
Returns the edge whose first two coordinates are p0 and p1.
An EdgeSetIntersector computes all the intersections between the edges in the set.
Definition: geomgraph/index/EdgeSetIntersector.h:40
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:32
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25