GEOS  3.9.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.
13  *
14  **********************************************************************
15  *
16  * Last port: operation/distance/DistanceOp.java r335 (JTS-1.12-)
17  *
18  **********************************************************************/
19
20 #ifndef GEOS_OP_DISTANCE_DISTANCEOP_H
21 #define GEOS_OP_DISTANCE_DISTANCEOP_H
22
23 #include <geos/export.h>
24
25 #include <geos/algorithm/PointLocator.h> // for composition
26 #include <geos/operation/distance/GeometryLocation.h>
27 #include <geos/geom/CoordinateSequence.h>
28
29 #include <array>
30 #include <vector>
31 #include <memory>
32
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 class Coordinate;
42 class Polygon;
43 class LineString;
44 class Point;
45 class Geometry;
46 }
47 }
48
49
50 namespace geos {
51 namespace operation { // geos::operation
52 namespace distance { // geos::operation::distance
53
72 class GEOS_DLL DistanceOp {
73 public:
84  static double distance(const geom::Geometry& g0,
85  const geom::Geometry& g1);
86
88  static double distance(const geom::Geometry* g0,
89  const geom::Geometry* g1);
90
101  static bool isWithinDistance(const geom::Geometry& g0,
102  const geom::Geometry& g1,
103  double distance);
104
117  static std::unique_ptr<geom::CoordinateSequence> nearestPoints(
118  const geom::Geometry* g0,
119  const geom::Geometry* g1);
120
122  DistanceOp(const geom::Geometry* g0, const geom::Geometry* g1);
123
132  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1);
133
144  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1,
145  double terminateDistance);
146
147  ~DistanceOp() = default;
148
154  double distance();
155
164  std::unique_ptr<geom::CoordinateSequence> nearestPoints();
165
166 private:
167
168  // input
169  std::array<geom::Geometry const*, 2> geom;
170  double terminateDistance;
171
172  // working
173  algorithm::PointLocator ptLocator;
174  std::array<std::unique_ptr<GeometryLocation>, 2> minDistanceLocation;
175  double minDistance;
176  bool computed = false;
177
178  void updateMinDistance(std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom, bool flip);
179
180  void computeMinDistance();
181
182  void computeContainmentDistance();
183
184  void computeInside(std::vector<std::unique_ptr<GeometryLocation>> & locs,
185  const std::vector<const geom::Polygon*>& polys,
186  std::array<std::unique_ptr<GeometryLocation>, 2> & locPtPoly);
187
188
193  void computeFacetDistance();
194
195  void computeMinDistanceLines(
196  const std::vector<const geom::LineString*>& lines0,
197  const std::vector<const geom::LineString*>& lines1,
198  std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom);
199
200  void computeMinDistancePoints(
201  const std::vector<const geom::Point*>& points0,
202  const std::vector<const geom::Point*>& points1,
203  std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom);
204
205  void computeMinDistanceLinesPoints(
206  const std::vector<const geom::LineString*>& lines0,
207  const std::vector<const geom::Point*>& points1,
208  std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom);
209
210  void computeMinDistance(const geom::LineString* line0,
211  const geom::LineString* line1,
212  std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom);
213
214  void computeMinDistance(const geom::LineString* line,
215  const geom::Point* pt,
216  std::array<std::unique_ptr<GeometryLocation>, 2> & locGeom);
217 };
218
219
220 } // namespace geos::operation::distance
221 } // namespace geos::operation
222 } // namespace geos
223
224 #ifdef _MSC_VER
225 #pragma warning(pop)
226 #endif
227
228 #endif // GEOS_OP_DISTANCE_DISTANCEOP_H
229
Find two points on two geom::Geometrys which lie within a given distance, or else are the nearest poi...
Definition: DistanceOp.h:72
Computes the topological relationship (Location) of a single point to a Geometry. ...
Definition: PointLocator.h:57
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Definition: LineString.h:68
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
Definition: Point.h:66