GEOS  3.13.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 #pragma once
21 
22 #include <geos/geom/Coordinate.h>
23 #include <geos/geom/CoordinateSequence.h>
24 #include <geos/geom/CoordinateList.h>
25 
26 #include <memory>
27 
28 // Forward declarations
29 namespace geos {
30 namespace geom {
31 //class PrecisionModel;
32 //class CoordinateSequence;
33 class CoordinateList;
34 class Geometry;
35 }
36 }
37 
38 namespace geos {
39 namespace operation { // geos::operation
40 namespace overlay { // geos::operation::overlay
41 namespace snap { // geos::operation::overlay::snap
42 
50 class GEOS_DLL LineStringSnapper {
51 
52 public:
53 
62  double nSnapTol)
63  :
64  srcPts(nSrcPts),
65  snapTolerance(nSnapTol),
66  allowSnappingToSourceVertices(false)
67  {
68  std::size_t s = srcPts.size();
69  isClosed = s < 2 ? false : srcPts[0].equals2D(srcPts[s - 1]);
70  }
71 
72  // Snap points are assumed to be all distinct points (a set would be better, uh ?)
73  std::unique_ptr<geom::CoordinateSequence> snapTo(const geom::Coordinate::ConstVect& snapPts);
74 
75  void
76  setAllowSnappingToSourceVertices(bool allow)
77  {
78  allowSnappingToSourceVertices = allow;
79  }
80 
81 private:
82 
83  const geom::CoordinateSequence& srcPts;
84 
85  double snapTolerance;
86 
87  bool allowSnappingToSourceVertices;
88  bool isClosed;
89 
90 
91  // Modifies first arg
92  void snapVertices(geom::CoordinateList& srcCoords,
93  const geom::Coordinate::ConstVect& snapPts);
94 
95 
96  // Returns snapPts.end() if no snap point is close enough (within snapTol distance)
97  geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt,
98  const geom::Coordinate::ConstVect& snapPts);
99 
115  void snapSegments(geom::CoordinateList& srcCoords,
116  const geom::Coordinate::ConstVect& snapPts);
117 
145  geom::CoordinateList::iterator findSegmentToSnap(
146  const geom::Coordinate& snapPt,
147  geom::CoordinateList::iterator from,
148  geom::CoordinateList::iterator too_far);
149 
150  geom::CoordinateList::iterator findVertexToSnap(
151  const geom::Coordinate& snapPt,
152  geom::CoordinateList::iterator from,
153  geom::CoordinateList::iterator too_far);
154 
155  // Declare type as noncopyable
156  LineStringSnapper(const LineStringSnapper& other) = delete;
157  LineStringSnapper& operator=(const LineStringSnapper& rhs) = delete;
158 };
159 
160 
161 } // namespace geos::operation::overlay::snap
162 } // namespace geos::operation::overlay
163 } // namespace geos::operation
164 } // namespace geos
165 
A list of Coordinates, which may be set to prevent repeated coordinates from occuring in the list.
Definition: CoordinateList.h:56
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:227
Snaps the vertices and segments of a LineString to a set of target snap vertices.
Definition: LineStringSnapper.h:50
LineStringSnapper(const geom::CoordinateSequence &nSrcPts, double nSnapTol)
Definition: LineStringSnapper.h:61
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25