GEOS  3.13.1
RelatePointLocator.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/algorithm/locate/PointOnGeometryLocator.h>
20 #include <geos/operation/relateng/AdjacentEdgeLocator.h>
21 #include <geos/operation/relateng/LinearBoundary.h>
22 #include <geos/geom/Coordinate.h>
23 #include <geos/geom/Location.h>
24 #include <geos/export.h>
25 
26 #include <memory>
27 #include <vector>
28 
29 // Forward declarations
30 namespace geos {
31 namespace algorithm {
32  namespace locate {
33  // class PointOnGeometryLocator;
34  }
35 }
36 namespace operation {
37  namespace relateng {
38  // class LinearBoundary;
39  // class AdjacentEdgeLocator;
40  }
41 }
42 namespace geom {
43  class CoordinateXY;
44  class Geometry;
45  class LineString;
46  class Point;
47 }
48 }
49 
50 
54 using geos::geom::CoordinateXY;
57 using geos::geom::Point;
59 
60 
61 namespace geos { // geos.
62 namespace operation { // geos.operation
63 namespace relateng { // geos.operation.relateng
64 
65 
86 class GEOS_DLL RelatePointLocator {
87 
88 private:
89 
90  // Members
91 
92  const Geometry* geom;
93  bool isPrepared = false;
94  const BoundaryNodeRule& boundaryRule;
95  std::unique_ptr<AdjacentEdgeLocator> adjEdgeLocator;
96  Coordinate::ConstXYSet points;
97  std::vector<const LineString *> lines;
98  std::vector<const Geometry *> polygons;
99  std::vector<std::unique_ptr<PointOnGeometryLocator>> polyLocator;
100  std::unique_ptr<LinearBoundary> lineBoundary;
101  bool isEmpty;
102 
103 
104 public:
105 
106  // Constructors
107 
108  RelatePointLocator(const Geometry* p_geom)
110  {};
111 
112  RelatePointLocator(const Geometry* p_geom, bool p_isPrepared, const BoundaryNodeRule& p_bnRule)
113  : geom(p_geom)
114  , isPrepared(p_isPrepared)
115  , boundaryRule(p_bnRule)
116  {
117  init(geom);
118  };
119 
120  void init(const Geometry* p_geom);
121 
122  bool hasBoundary() const;
123 
124  void extractElements(const Geometry* geom);
125 
126  void addPoint(const Point* pt);
127 
128  void addLine(const LineString* line);
129 
130  void addPolygonal(const Geometry* polygonal);
131 
132  Location locate(const CoordinateXY* p);
133 
134  int locateLineEndWithDim(const CoordinateXY* p);
135 
136  /*
137  * Locates a point which is known to be a node of the geometry
138  * (i.e. a vertex or on an edge).
139  *
140  * @param p the node point to locate
141  * @param parentPolygonal the polygon the point is a node of
142  * @return the location of the node point
143  */
144  Location locateNode(const CoordinateXY* p, const Geometry* parentPolygonal);
145 
154  int locateNodeWithDim(const CoordinateXY* p, const Geometry* parentPolygonal);
155 
167  int locateWithDim(const CoordinateXY* p);
168 
169 
170 private:
171 
172  // Methods
173 
187  int locateWithDim(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
188 
189  int computeDimLocation(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
190 
191  Location locateOnPoints(const CoordinateXY* p) const;
192 
193  Location locateOnLines(const CoordinateXY* p, bool isNode);
194 
195  Location locateOnLine(const CoordinateXY* p, /*bool isNode,*/ const LineString* l);
196 
197  Location locateOnPolygons(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
198 
199  Location locateOnPolygonal(const CoordinateXY* p,
200  bool isNode,
201  const Geometry* parentPolygonal,
202  std::size_t index);
203 
204  PointOnGeometryLocator * getLocator(std::size_t index);
205 
206 
207 
208 };
209 
210 } // namespace geos.operation.relateng
211 } // namespace geos.operation
212 } // namespace geos
213 
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition: BoundaryNodeRule.h:52
static const BoundaryNodeRule & getBoundaryRuleMod2()
The Mod-2 Boundary Node Rule (which is the rule specified in the OGC SFS).
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition: PointOnGeometryLocator.h:36
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
Definition: LineString.h:66
Definition: Point.h:61
Definition: RelatePointLocator.h:86
int locateNodeWithDim(const CoordinateXY *p, const Geometry *parentPolygonal)
int locateWithDim(const CoordinateXY *p)
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