GEOS  3.5.0
GeometryGraph.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 #ifndef GEOS_GEOMGRAPH_GEOMETRYGRAPH_H
23 #define GEOS_GEOMGRAPH_GEOMETRYGRAPH_H
24 
25 #include <geos/export.h>
26 #include <map>
27 #include <vector>
28 #include <memory>
29 
30 #include <geos/geom/Coordinate.h>
31 #include <geos/geom/CoordinateSequence.h> // for auto_ptr<CoordinateSequence>
32 #include <geos/geomgraph/PlanarGraph.h>
33 #include <geos/geom/LineString.h> // for LineStringLT
34 
35 #include <geos/inline.h>
36 
37 #ifdef _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
40 #endif
41 
42 // Forward declarations
43 namespace geos {
44  namespace geom {
45  class LineString;
46  class LinearRing;
47  class Polygon;
48  class Geometry;
49  class GeometryCollection;
50  class Point;
51  class Envelope;
52  }
53  namespace algorithm {
54  class LineIntersector;
55  class BoundaryNodeRule;
56  }
57  namespace geomgraph {
58  class Edge;
59  class Node;
60  namespace index {
61  class SegmentIntersector;
62  class EdgeSetIntersector;
63  }
64  }
65 }
66 
67 namespace geos {
68 namespace geomgraph { // geos.geomgraph
69 
73 class GEOS_DLL GeometryGraph: public PlanarGraph
74 {
75 using PlanarGraph::add;
77 
78 private:
79 
80  const geom::Geometry* parentGeom;
81 
90 //std::map<const geom::LineString*,Edge*,geom::LineStringLT> lineEdgeMap;
91  std::map<const geom::LineString*, Edge*> lineEdgeMap;
92 
97  bool useBoundaryDeterminationRule;
98 
99  const algorithm::BoundaryNodeRule& boundaryNodeRule;
100 
105  int argIndex;
106 
108  std::auto_ptr< geom::CoordinateSequence > boundaryPoints;
109 
110  std::auto_ptr< std::vector<Node*> > boundaryNodes;
111 
112  bool hasTooFewPointsVar;
113 
114  geom::Coordinate invalidPoint;
115 
117  index::EdgeSetIntersector* createEdgeSetIntersector();
118 
119  void add(const geom::Geometry *g);
120  // throw(UnsupportedOperationException);
121 
122  void addCollection(const geom::GeometryCollection *gc);
123 
124  void addPoint(const geom::Point *p);
125 
126  void addPolygonRing(const geom::LinearRing *lr,
127  int cwLeft, int cwRight);
128 
129  void addPolygon(const geom::Polygon *p);
130 
131  void addLineString(const geom::LineString *line);
132 
133  void insertPoint(int argIndex, const geom::Coordinate& coord,
134  int onLocation);
135 
143  void insertBoundaryPoint(int argIndex, const geom::Coordinate& coord);
144 
145  void addSelfIntersectionNodes(int argIndex);
146 
154  void addSelfIntersectionNode(int argIndex,
155  const geom::Coordinate& coord, int loc);
156 
157  // Declare type as noncopyable
158  GeometryGraph(const GeometryGraph& other);
159  GeometryGraph& operator=(const GeometryGraph& rhs);
160 
161 public:
162 
163  static bool isInBoundary(int boundaryCount);
164 
165  static int determineBoundary(int boundaryCount);
166 
167  static int determineBoundary(
168  const algorithm::BoundaryNodeRule& boundaryNodeRule,
169  int boundaryCount);
170 
171  GeometryGraph();
172 
173  GeometryGraph(int newArgIndex, const geom::Geometry *newParentGeom);
174 
175  GeometryGraph(int newArgIndex, const geom::Geometry *newParentGeom,
176  const algorithm::BoundaryNodeRule& boundaryNodeRule);
177 
178  virtual ~GeometryGraph();
179 
180 
181  const geom::Geometry* getGeometry();
182 
184  std::vector<Node*>* getBoundaryNodes();
185 
186  void getBoundaryNodes(std::vector<Node*>&bdyNodes);
187 
189  geom::CoordinateSequence* getBoundaryPoints();
190 
191  Edge* findEdge(const geom::LineString *line);
192 
193  void computeSplitEdges(std::vector<Edge*> *edgelist);
194 
195  void addEdge(Edge *e);
196 
197  void addPoint(geom::Coordinate& pt);
198 
214  index::SegmentIntersector* computeSelfNodes(
216  bool computeRingSelfNodes,
217  const geom::Envelope *env=0)
218  {
219  return computeSelfNodes(*li, computeRingSelfNodes, env);
220  }
221 
222  // Quick inline calling the function above, the above should probably
223  // be deprecated.
224  index::SegmentIntersector* computeSelfNodes(
226  bool computeRingSelfNodes, const geom::Envelope *env=0);
227 
228  index::SegmentIntersector* computeEdgeIntersections(GeometryGraph *g,
229  algorithm::LineIntersector *li, bool includeProper,
230  const geom::Envelope *env=0);
231 
232  std::vector<Edge*> *getEdges();
233 
234  bool hasTooFewPoints();
235 
236  const geom::Coordinate& getInvalidPoint();
237 
238  const algorithm::BoundaryNodeRule& getBoundaryNodeRule() const
239  { return boundaryNodeRule; }
240 
241 };
242 
243 
244 } // namespace geos.geomgraph
245 } // namespace geos
246 
247 #ifdef _MSC_VER
248 #pragma warning(pop)
249 #endif
250 
251 #ifdef GEOS_INLINE
252 # include "geos/geomgraph/GeometryGraph.inl"
253 #endif
254 
255 #endif // ifndef GEOS_GEOMGRAPH_GEOMETRYGRAPH_H