GEOS  3.8.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
27 #include <array>
28 #include <vector>
29
30 #ifdef _MSC_VER
31 #pragma warning(push)
32 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33 #endif
34
35 // Forward declarations
36 namespace geos {
37 namespace geom {
38 class Coordinate;
39 class Polygon;
40 class LineString;
41 class Point;
42 class Geometry;
43 class CoordinateSequence;
44 }
45 namespace operation {
46 namespace distance {
47 class GeometryLocation;
48 }
49 }
50 }
51
52
53 namespace geos {
54 namespace operation { // geos::operation
55 namespace distance { // geos::operation::distance
56
75 class GEOS_DLL DistanceOp {
76 public:
87  static double distance(const geom::Geometry& g0,
88  const geom::Geometry& g1);
89
91  static double distance(const geom::Geometry* g0,
92  const geom::Geometry* g1);
93
104  static bool isWithinDistance(const geom::Geometry& g0,
105  const geom::Geometry& g1,
106  double distance);
107
120  static geom::CoordinateSequence* nearestPoints(
121  const geom::Geometry* g0,
122  const geom::Geometry* g1);
123
137  static geom::CoordinateSequence* closestPoints(
138  const geom::Geometry* g0,
139  const geom::Geometry* g1);
140
142  DistanceOp(const geom::Geometry* g0, const geom::Geometry* g1);
143
152  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1);
153
164  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1,
165  double terminateDistance);
166
167  ~DistanceOp();
168
174  double distance();
175
185  geom::CoordinateSequence* closestPoints();
186
195  geom::CoordinateSequence* nearestPoints();
196
197 private:
198
211  std::vector<GeometryLocation*>* nearestLocations();
212
213  // input
214  std::array<geom::Geometry const*, 2> geom;
215  double terminateDistance;
216
217  // working
218  algorithm::PointLocator ptLocator;
219  // TODO: use unique_ptr
220  std::vector<GeometryLocation*>* minDistanceLocation;
221  double minDistance;
222
223  // memory management
224  std::vector<geom::Coordinate*> newCoords;
225
226
227  void updateMinDistance(std::vector<GeometryLocation*>& locGeom,
228  bool flip);
229
230  void computeMinDistance();
231
232  void computeContainmentDistance();
233
234  void computeInside(std::vector<GeometryLocation*>* locs,
235  const std::vector<const geom::Polygon*>& polys,
236  std::vector<GeometryLocation*>* locPtPoly);
237
238  void computeInside(GeometryLocation* ptLoc,
239  const geom::Polygon* poly,
240  std::vector<GeometryLocation*>* locPtPoly);
241
246  void computeFacetDistance();
247
248  void computeMinDistanceLines(
249  const std::vector<const geom::LineString*>& lines0,
250  const std::vector<const geom::LineString*>& lines1,
251  std::vector<GeometryLocation*>& locGeom);
252
253  void computeMinDistancePoints(
254  const std::vector<const geom::Point*>& points0,
255  const std::vector<const geom::Point*>& points1,
256  std::vector<GeometryLocation*>& locGeom);
257
258  void computeMinDistanceLinesPoints(
259  const std::vector<const geom::LineString*>& lines0,
260  const std::vector<const geom::Point*>& points1,
261  std::vector<GeometryLocation*>& locGeom);
262
263  void computeMinDistance(const geom::LineString* line0,
264  const geom::LineString* line1,
265  std::vector<GeometryLocation*>& locGeom);
266
267  void computeMinDistance(const geom::LineString* line,
268  const geom::Point* pt,
269  std::vector<GeometryLocation*>& locGeom);
270 };
271
272
273 } // namespace geos::operation::distance
274 } // namespace geos::operation
275 } // namespace geos
276
277 #ifdef _MSC_VER
278 #pragma warning(pop)
279 #endif
280
281 #endif // GEOS_OP_DISTANCE_DISTANCEOP_H
282
Find two points on two Geometrys which lie within a given distance, or else are the nearest points on...
Definition: DistanceOp.h:75
Represents the location of a point on a Geometry.
Definition: GeometryLocation.h:50
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:187
Definition: LineString.h:69
Represents a linear polygon, which may include holes.
Definition: Polygon.h:65
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Definition: Point.h:66