GEOS  3.9.1dev
LineStringSnapper.h
Go to the documentation of this file.
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>
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 
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
78  {
79  allowSnappingToSourceVertices = allow;
80  }
81 
82 private:
83 
85 
86  double snapTolerance;
87 
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 
146  geom::CoordinateList::iterator findSegmentToSnap(
147  const geom::Coordinate& snapPt,
150 
151  geom::CoordinateList::iterator findVertexToSnap(
152  const geom::Coordinate& snapPt,
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. ...
#define GEOS_DLL
Definition: export.h:28
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.
std::list< Coordinate >::iterator iterator
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...
LineStringSnapper(const geom::Coordinate::Vect &nSrcPts, double nSnapTol)