GEOS  3.11.0rc0
TaggedLineStringSimplifier.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: simplify/TaggedLineStringSimplifier.java r536 (JTS-1.12+)
16  *
17  **********************************************************************
18  *
19  * NOTES: This class can be optimized to work with vector<Coordinate*>
20  * rather then with CoordinateSequence
21  *
22  **********************************************************************/
23 
24 #pragma once
25 
26 #include <geos/export.h>
27 #include <cstddef>
28 #include <vector>
29 #include <memory>
30 
31 #ifdef _MSC_VER
32 #pragma warning(push)
33 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34 #endif
35 
36 // Forward declarations
37 namespace geos {
38 namespace algorithm {
39 class LineIntersector;
40 }
41 namespace geom {
42 class CoordinateSequence;
43 class LineSegment;
44 }
45 namespace simplify {
46 class TaggedLineSegment;
47 class TaggedLineString;
48 class LineSegmentIndex;
49 }
50 }
51 
52 namespace geos {
53 namespace simplify { // geos::simplify
54 
55 
63 
64 public:
65 
66  TaggedLineStringSimplifier(LineSegmentIndex* inputIndex,
67  LineSegmentIndex* outputIndex);
68 
77  void setDistanceTolerance(double d);
78 
86 
87 
88 private:
89 
90  // externally owned
91  LineSegmentIndex* inputIndex;
92 
93  // externally owned
94  LineSegmentIndex* outputIndex;
95 
96  std::unique_ptr<algorithm::LineIntersector> li;
97 
99  TaggedLineString* line;
100 
101  const geom::CoordinateSequence* linePts;
102 
103  double distanceTolerance;
104 
105  void simplifySection(std::size_t i, std::size_t j,
106  std::size_t depth);
107 
108  static std::size_t findFurthestPoint(
109  const geom::CoordinateSequence* pts,
110  std::size_t i, std::size_t j,
111  double& maxDistance);
112 
113  bool hasBadIntersection(const TaggedLineString* parentLine,
114  const std::pair<std::size_t, std::size_t>& sectionIndex,
115  const geom::LineSegment& candidateSeg);
116 
117  bool hasBadInputIntersection(const TaggedLineString* parentLine,
118  const std::pair<std::size_t, std::size_t>& sectionIndex,
119  const geom::LineSegment& candidateSeg);
120 
121  bool hasBadOutputIntersection(const geom::LineSegment& candidateSeg);
122 
123  bool hasInteriorIntersection(const geom::LineSegment& seg0,
124  const geom::LineSegment& seg1) const;
125 
126  std::unique_ptr<TaggedLineSegment> flatten(
127  std::size_t start, std::size_t end);
128 
137  static bool isInLineSection(
138  const TaggedLineString* parentLine,
139  const std::pair<std::size_t, std::size_t>& sectionIndex,
140  const TaggedLineSegment* seg);
141 
149  void remove(const TaggedLineString* line,
150  std::size_t start,
151  std::size_t end);
152 
153 };
154 
155 inline void
157 {
158  distanceTolerance = d;
159 }
160 
161 } // namespace geos::simplify
162 } // namespace geos
163 
164 #ifdef _MSC_VER
165 #pragma warning(pop)
166 #endif
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Definition: LineSegment.h:60
A geom::LineSegment which is tagged with its location in a geom::Geometry.
Definition: TaggedLineSegment.h:53
Simplifies a TaggedLineString, preserving topology (in the sense that no new intersections are introd...
Definition: TaggedLineStringSimplifier.h:62
void simplify(TaggedLineString *line)
void setDistanceTolerance(double d)
Sets the distance tolerance for the simplification.
Definition: TaggedLineStringSimplifier.h:156
Contains and owns a list of TaggedLineSegments.
Definition: TaggedLineString.h:57
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25