GEOS  3.4.2
DistanceOp.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 #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 <vector>
28 
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32 #endif
33 
34 // Forward declarations
35 namespace geos {
36  namespace geom {
37  class Coordinate;
38  class Polygon;
39  class LineString;
40  class Point;
41  class Geometry;
42  class CoordinateSequence;
43  }
44  namespace operation {
45  namespace distance {
46  class GeometryLocation;
47  }
48  }
49 }
50 
51 
52 namespace geos {
53 namespace operation { // geos::operation
54 namespace distance { // geos::operation::distance
55 
74 class GEOS_DLL DistanceOp {
75 public:
86  static double distance(const geom::Geometry& g0,
87  const geom::Geometry& g1);
88 
90  static double distance(const geom::Geometry *g0,
91  const geom::Geometry *g1);
92 
103  static bool isWithinDistance(const geom::Geometry& g0,
104  const geom::Geometry& g1,
105  double distance);
106 
119  static geom::CoordinateSequence* nearestPoints(
120  const geom::Geometry *g0,
121  const geom::Geometry *g1);
122 
136  static geom::CoordinateSequence* closestPoints(
137  const geom::Geometry *g0,
138  const geom::Geometry *g1);
139 
141  DistanceOp(const geom::Geometry *g0, const geom::Geometry *g1);
142 
151  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1);
152 
163  DistanceOp(const geom::Geometry& g0, const geom::Geometry& g1,
164  double terminateDistance);
165 
166  ~DistanceOp();
167 
173  double distance();
174 
184  geom::CoordinateSequence* closestPoints();
185 
194  geom::CoordinateSequence* nearestPoints();
195 
196 private:
197 
210  std::vector<GeometryLocation*>* nearestLocations();
211 
212  // input (TODO: use two references instead..)
213  std::vector<geom::Geometry const*> geom;
214  double terminateDistance;
215 
216  // working
217  algorithm::PointLocator ptLocator;
218  // TODO: use auto_ptr
219  std::vector<GeometryLocation*> *minDistanceLocation;
220  double minDistance;
221 
222  // memory management
223  std::vector<geom::Coordinate *> newCoords;
224 
225 
226  void updateMinDistance(std::vector<GeometryLocation*>& locGeom,
227  bool flip);
228 
229  void computeMinDistance();
230 
231  void computeContainmentDistance();
232 
233  void computeInside(std::vector<GeometryLocation*> *locs,
234  const std::vector<const geom::Polygon*>& polys,
235  std::vector<GeometryLocation*> *locPtPoly);
236 
237  void computeInside(GeometryLocation *ptLoc,
238  const geom::Polygon *poly,
239  std::vector<GeometryLocation*> *locPtPoly);
240 
245  void computeFacetDistance();
246 
247  void computeMinDistanceLines(
248  const std::vector<const geom::LineString*>& lines0,
249  const std::vector<const geom::LineString*>& lines1,
250  std::vector<GeometryLocation*>& locGeom);
251 
252  void computeMinDistancePoints(
253  const std::vector<const geom::Point*>& points0,
254  const std::vector<const geom::Point*>& points1,
255  std::vector<GeometryLocation*>& locGeom);
256 
257  void computeMinDistanceLinesPoints(
258  const std::vector<const geom::LineString*>& lines0,
259  const std::vector<const geom::Point*>& points1,
260  std::vector<GeometryLocation*>& locGeom);
261 
262  void computeMinDistance(const geom::LineString *line0,
263  const geom::LineString *line1,
264  std::vector<GeometryLocation*>& locGeom);
265 
266  void computeMinDistance(const geom::LineString *line,
267  const geom::Point *pt,
268  std::vector<GeometryLocation*>& locGeom);
269 };
270 
271 
272 } // namespace geos::operation::distance
273 } // namespace geos::operation
274 } // namespace geos
275 
276 #ifdef _MSC_VER
277 #pragma warning(pop)
278 #endif
279 
280 #endif // GEOS_OP_DISTANCE_DISTANCEOP_H
281 
Find two points on two Geometrys which lie within a given distance, or else are the nearest points on...
Definition: DistanceOp.h:74
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:167
Definition: LineString.h:70
Represents a linear polygon, which may include holes.
Definition: Polygon.h:66
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
Definition: Point.h:67