GEOS 3.15.0dev
DistanceOp.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) 2006 Refractions Research Inc.
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 * Last port: operation/distance/DistanceOp.java r335 (JTS-1.12-)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23
24#include <geos/algorithm/PointLocator.h> // for composition
25#include <geos/operation/distance/GeometryLocation.h>
26#include <geos/geom/CoordinateSequence.h>
27
28#include <array>
29#include <vector>
30#include <memory>
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geom {
40class CircularString;
41class Coordinate;
42class Polygon;
43class LineString;
44class Point;
45class Geometry;
46class SimpleCurve;
47class Surface;
48}
49}
50
51
52namespace geos {
53namespace operation { // geos::operation
54namespace distance { // geos::operation::distance
55
76class GEOS_DLL DistanceOp {
77public:
88 static double distance(const geom::Geometry& g0,
89 const geom::Geometry& g1);
90
92 static double distance(const geom::Geometry* g0,
93 const geom::Geometry* g1);
94
105 static bool isWithinDistance(const geom::Geometry& g0,
106 const geom::Geometry& g1,
107 double distance);
108
115 const std::array<GeometryLocation, 2>& nearestLocations();
116
129 static std::unique_ptr<geom::CoordinateSequence> nearestPoints(
130 const geom::Geometry* g0,
131 const geom::Geometry* g1);
132
135
145
157 double terminateDistance);
158
159 ~DistanceOp() = default;
160
166 double distance();
167
176 std::unique_ptr<geom::CoordinateSequence> nearestPoints();
177
178private:
179
180 // input
181 std::array<geom::Geometry const*, 2> geom;
182 double terminateDistance;
183
184 // working
185 algorithm::PointLocator ptLocator;
186 std::array<GeometryLocation, 2> minDistanceLocation;
187 double minDistance;
188 bool computed = false;
189
190 void updateMinDistance(std::array<GeometryLocation, 2> & locGeom, bool flip);
191
192 void computeMinDistance();
193
194 void computeContainmentDistance();
195
196 void computeInside(std::vector<GeometryLocation> & locs,
197 const std::vector<const geom::Surface*>& polys,
198 std::array<GeometryLocation, 2> & locPtPoly);
199
200
205 void computeFacetDistance();
206
207 void computeMinDistanceLines(
208 const std::vector<const geom::SimpleCurve*>& lines0,
209 const std::vector<const geom::SimpleCurve*>& lines1,
210 std::array<GeometryLocation, 2> & locGeom);
211
212 void computeMinDistancePoints(
213 const std::vector<const geom::Point*>& points0,
214 const std::vector<const geom::Point*>& points1,
215 std::array<GeometryLocation, 2> & locGeom);
216
217 void computeMinDistanceLinesPoints(
218 const std::vector<const geom::SimpleCurve*>& lines0,
219 const std::vector<const geom::Point*>& points1,
220 std::array<GeometryLocation, 2> & locGeom);
221
222 void computeMinDistance(const geom::CircularString* cs0,
223 const geom::LineString* line1,
224 std::array<GeometryLocation, 2> & locGeom);
225
226 void computeMinDistance(const geom::LineString* line0,
227 const geom::CircularString* cs1,
228 std::array<GeometryLocation, 2> & locGeom);
229
230 void computeMinDistance(const geom::LineString* line0,
231 const geom::LineString* line1,
232 std::array<GeometryLocation, 2> & locGeom);
233
234 void computeMinDistance(const geom::CircularString* cs0,
235 const geom::CircularString* cs1,
236 std::array<GeometryLocation, 2> & locGeom);
237
238 void computeMinDistance(const geom::LineString* line,
239 const geom::Point* pt,
240 std::array<GeometryLocation, 2> & locGeom);
241
242 void computeMinDistance(const geom::CircularString* cs,
243 const geom::Point* pt,
244 std::array<GeometryLocation, 2> & locGeom);
245};
246
247
248} // namespace geos::operation::distance
249} // namespace geos::operation
250} // namespace geos
251
252#ifdef _MSC_VER
253#pragma warning(pop)
254#endif
255
Computes the topological relationship (Location) of a single point to a Geometry.
Definition PointLocator.h:58
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
Definition LineString.h:66
Definition Point.h:61
Find two points on two geom::Geometrys which lie within a given distance, or else are the nearest poi...
Definition DistanceOp.h:76
static double distance(const geom::Geometry *g0, const geom::Geometry *g1)
static bool isWithinDistance(const geom::Geometry &g0, const geom::Geometry &g1, double distance)
Test whether two geometries lie within a given distance of each other.
DistanceOp(const geom::Geometry &g0, const geom::Geometry &g1)
Constructs a DistanceOp that computes the distance and nearest points between the two specified geome...
const std::array< GeometryLocation, 2 > & nearestLocations()
static std::unique_ptr< geom::CoordinateSequence > nearestPoints(const geom::Geometry *g0, const geom::Geometry *g1)
DistanceOp(const geom::Geometry &g0, const geom::Geometry &g1, double terminateDistance)
Constructs a DistanceOp that computes the distance and nearest points between the two specified geome...
static double distance(const geom::Geometry &g0, const geom::Geometry &g1)
Compute the distance between the nearest points of two geometries.
DistanceOp(const geom::Geometry *g0, const geom::Geometry *g1)
std::unique_ptr< geom::CoordinateSequence > nearestPoints()
Basic namespace for all GEOS functionalities.
Definition geos.h:38