GEOS 3.14.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 Coordinate;
41class Polygon;
42class LineString;
43class Point;
44class Geometry;
45}
46}
47
48
49namespace geos {
50namespace operation { // geos::operation
51namespace distance { // geos::operation::distance
52
73class GEOS_DLL DistanceOp {
74public:
85 static double distance(const geom::Geometry& g0,
86 const geom::Geometry& g1);
87
89 static double distance(const geom::Geometry* g0,
90 const geom::Geometry* g1);
91
102 static bool isWithinDistance(const geom::Geometry& g0,
103 const geom::Geometry& g1,
104 double distance);
105
118 static std::unique_ptr<geom::CoordinateSequence> nearestPoints(
119 const geom::Geometry* g0,
120 const geom::Geometry* g1);
121
124
134
146 double terminateDistance);
147
148 ~DistanceOp() = default;
149
155 double distance();
156
165 std::unique_ptr<geom::CoordinateSequence> nearestPoints();
166
167private:
168
169 // input
170 std::array<geom::Geometry const*, 2> geom;
171 double terminateDistance;
172
173 // working
174 algorithm::PointLocator ptLocator;
175 std::array<GeometryLocation, 2> minDistanceLocation;
176 double minDistance;
177 bool computed = false;
178
179 void updateMinDistance(std::array<GeometryLocation, 2> & locGeom, bool flip);
180
181 void computeMinDistance();
182
183 void computeContainmentDistance();
184
185 void computeInside(std::vector<GeometryLocation> & locs,
186 const std::vector<const geom::Polygon*>& polys,
187 std::array<GeometryLocation, 2> & locPtPoly);
188
189
194 void computeFacetDistance();
195
196 void computeMinDistanceLines(
197 const std::vector<const geom::LineString*>& lines0,
198 const std::vector<const geom::LineString*>& lines1,
199 std::array<GeometryLocation, 2> & locGeom);
200
201 void computeMinDistancePoints(
202 const std::vector<const geom::Point*>& points0,
203 const std::vector<const geom::Point*>& points1,
204 std::array<GeometryLocation, 2> & locGeom);
205
206 void computeMinDistanceLinesPoints(
207 const std::vector<const geom::LineString*>& lines0,
208 const std::vector<const geom::Point*>& points1,
209 std::array<GeometryLocation, 2> & locGeom);
210
211 void computeMinDistance(const geom::LineString* line0,
212 const geom::LineString* line1,
213 std::array<GeometryLocation, 2> & locGeom);
214
215 void computeMinDistance(const geom::LineString* line,
216 const geom::Point* pt,
217 std::array<GeometryLocation, 2> & locGeom);
218};
219
220
221} // namespace geos::operation::distance
222} // namespace geos::operation
223} // namespace geos
224
225#ifdef _MSC_VER
226#pragma warning(pop)
227#endif
228
Computes the topological relationship (Location) of a single point to a Geometry.
Definition PointLocator.h:56
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
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:73
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...
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:39