GEOS  3.8.0dev
LineStringSnapper.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009-2010 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/overlay/snap/LineStringSnapper.java r320 (JTS-1.12)
17  *
18  **********************************************************************/
19 
20 #ifndef GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
21 #define GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
22 
23 #include <geos/geom/Coordinate.h>
24 #include <geos/geom/CoordinateSequence.h>
25 #include <geos/geom/CoordinateList.h>
26 
27 #include <memory>
28 
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 //class PrecisionModel;
33 //class CoordinateSequence;
34 class CoordinateList;
35 class Geometry;
36 }
37 }
38 
39 namespace geos {
40 namespace operation { // geos::operation
41 namespace overlay { // geos::operation::overlay
42 namespace snap { // geos::operation::overlay::snap
43 
51 class GEOS_DLL LineStringSnapper {
52 
53 public:
54 
63  double nSnapTol)
64  :
65  srcPts(nSrcPts),
66  snapTolerance(nSnapTol),
67  allowSnappingToSourceVertices(false)
68  {
69  size_t s = srcPts.size();
70  isClosed = s < 2 ? false : srcPts[0].equals2D(srcPts[s - 1]);
71  }
72 
73  // Snap points are assumed to be all distinct points (a set would be better, uh ?)
74  std::unique_ptr<geom::Coordinate::Vect> snapTo(const geom::Coordinate::ConstVect& snapPts);
75 
76  void
77  setAllowSnappingToSourceVertices(bool allow)
78  {
79  allowSnappingToSourceVertices = allow;
80  }
81 
82 private:
83 
84  const geom::Coordinate::Vect& srcPts;
85 
86  double snapTolerance;
87 
88  bool allowSnappingToSourceVertices;
89  bool isClosed;
90 
91 
92  // Modifies first arg
93  void snapVertices(geom::CoordinateList& srcCoords,
94  const geom::Coordinate::ConstVect& snapPts);
95 
96 
97  // Returns snapPts.end() if no snap point is close enough (within snapTol distance)
98  geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt,
99  const geom::Coordinate::ConstVect& snapPts);
100 
116  void snapSegments(geom::CoordinateList& srcCoords,
117  const geom::Coordinate::ConstVect& snapPts);
118 
122  //
146  geom::CoordinateList::iterator findSegmentToSnap(
147  const geom::Coordinate& snapPt,
148  geom::CoordinateList::iterator from,
149  geom::CoordinateList::iterator too_far);
150 
151  geom::CoordinateList::iterator findVertexToSnap(
152  const geom::Coordinate& snapPt,
153  geom::CoordinateList::iterator from,
154  geom::CoordinateList::iterator too_far);
155 
156  // Declare type as noncopyable
157  LineStringSnapper(const LineStringSnapper& other) = delete;
158  LineStringSnapper& operator=(const LineStringSnapper& rhs) = delete;
159 };
160 
161 
162 } // namespace geos::operation::overlay::snap
163 } // namespace geos::operation::overlay
164 } // namespace geos::operation
165 } // namespace geos
166 
167 #endif // GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H
168 
Snaps the vertices and segments of a LineString to a set of target snap vertices. ...
Definition: LineStringSnapper.h:51
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:71
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
std::vector< Coordinate > Vect
A vector of Coordinate objects (real object, not pointers)
Definition: Coordinate.h:77
A list of Coordinates, which may be set to prevent repeated coordinates from occuring in the list...
Definition: CoordinateList.h:55
LineStringSnapper(const geom::Coordinate::Vect &nSrcPts, double nSnapTol)
Definition: LineStringSnapper.h:62