GEOS 3.14.0dev
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
30namespace geos {
31namespace algorithm {
32 namespace locate {
33 // class PointOnGeometryLocator;
34 }
35}
36namespace operation {
37 namespace relateng {
38 // class LinearBoundary;
39 // class AdjacentEdgeLocator;
40 }
41}
42namespace geom {
43 class CoordinateXY;
44 class Geometry;
45 class LineString;
46 class Point;
47}
48}
49
50namespace geos { // geos.
51namespace operation { // geos.operation
52namespace relateng { // geos.operation.relateng
53
54
75class GEOS_DLL RelatePointLocator {
79 using CoordinateXY = geos::geom::CoordinateXY;
84
85private:
86
87 // Members
88
89 const Geometry* geom;
90 bool isPrepared = false;
91 const BoundaryNodeRule& boundaryRule;
92 std::unique_ptr<AdjacentEdgeLocator> adjEdgeLocator;
93 Coordinate::ConstXYSet points;
94 std::vector<const LineString *> lines;
95 std::vector<const Geometry *> polygons;
96 std::vector<std::unique_ptr<PointOnGeometryLocator>> polyLocator;
97 std::unique_ptr<LinearBoundary> lineBoundary;
98 bool isEmpty;
99
100
101public:
102
103 // Constructors
104
105 RelatePointLocator(const Geometry* p_geom)
106 : RelatePointLocator(p_geom, false, BoundaryNodeRule::getBoundaryRuleMod2())
107 {};
108
109 RelatePointLocator(const Geometry* p_geom, bool p_isPrepared, const BoundaryNodeRule& p_bnRule)
110 : geom(p_geom)
111 , isPrepared(p_isPrepared)
112 , boundaryRule(p_bnRule)
113 {
114 init(geom);
115 };
116
117 void init(const Geometry* p_geom);
118
119 bool hasBoundary() const;
120
121 void extractElements(const Geometry* geom);
122
123 void addPoint(const Point* pt);
124
125 void addLine(const LineString* line);
126
127 void addPolygonal(const Geometry* polygonal);
128
129 Location locate(const CoordinateXY* p);
130
131 int locateLineEndWithDim(const CoordinateXY* p);
132
133 /*
134 * Locates a point which is known to be a node of the geometry
135 * (i.e. a vertex or on an edge).
136 *
137 * @param p the node point to locate
138 * @param parentPolygonal the polygon the point is a node of
139 * @return the location of the node point
140 */
141 Location locateNode(const CoordinateXY* p, const Geometry* parentPolygonal);
142
151 int locateNodeWithDim(const CoordinateXY* p, const Geometry* parentPolygonal);
152
164 int locateWithDim(const CoordinateXY* p);
165
166
167private:
168
169 // Methods
170
184 int locateWithDim(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
185
186 int computeDimLocation(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
187
188 Location locateOnPoints(const CoordinateXY* p) const;
189
190 Location locateOnLines(const CoordinateXY* p, bool isNode);
191
192 Location locateOnLine(const CoordinateXY* p, /*bool isNode,*/ const LineString* l);
193
194 Location locateOnPolygons(const CoordinateXY* p, bool isNode, const Geometry* parentPolygonal);
195
196 Location locateOnPolygonal(const CoordinateXY* p,
197 bool isNode,
198 const Geometry* parentPolygonal,
199 std::size_t index);
200
201 PointOnGeometryLocator * getLocator(std::size_t index);
202
203
204
205};
206
207} // namespace geos.operation.relateng
208} // namespace geos.operation
209} // namespace geos
210
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition BoundaryNodeRule.h:52
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:75
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 geos.h:39