/src/geos/include/geos/precision/PrecisionReducerTransformer.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca> |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | **********************************************************************/ |
14 | | |
15 | | #pragma once |
16 | | |
17 | | #include <geos/export.h> |
18 | | #include <memory> |
19 | | |
20 | | #include <geos/geom/util/GeometryTransformer.h> |
21 | | |
22 | | // Forward declarations |
23 | | namespace geos { |
24 | | namespace geom { |
25 | | class PrecisionModel; |
26 | | class Geometry; |
27 | | } |
28 | | } |
29 | | |
30 | | namespace geos { |
31 | | namespace precision { // geos.precision |
32 | | |
33 | | /** \brief |
34 | | * Reduces the precision of a {@link geom::Geometry} |
35 | | * according to the supplied {@link geom::PrecisionModel}, without |
36 | | * attempting to preserve valid topology. |
37 | | * |
38 | | * The topology of the resulting geometry may be invalid if |
39 | | * topological collapse occurs due to coordinates being shifted. |
40 | | * It is up to the client to check this and handle it if necessary. |
41 | | * Collapses may not matter for some uses. An example |
42 | | * is simplifying the input to the buffer algorithm. |
43 | | * The buffer algorithm does not depend on the validity of the input geometry. |
44 | | * |
45 | | */ |
46 | | class GEOS_DLL PrecisionReducerTransformer : public geom::util::GeometryTransformer { |
47 | | |
48 | | private: |
49 | | |
50 | | const geom::PrecisionModel& targetPM; |
51 | | bool isRemoveCollapsed; |
52 | | |
53 | | std::unique_ptr<geom::Geometry> reduceArea(const geom::Geometry* geom) const; |
54 | | |
55 | | static void extend( |
56 | | geom::CoordinateSequence& coords, |
57 | | std::size_t minLength); |
58 | | |
59 | | |
60 | | public: |
61 | | |
62 | | PrecisionReducerTransformer( |
63 | | const geom::PrecisionModel& p_targetPM, |
64 | | bool p_isRemoveCollapsed = false) |
65 | 0 | : targetPM(p_targetPM) |
66 | 0 | , isRemoveCollapsed(p_isRemoveCollapsed) |
67 | 0 | {}; |
68 | | |
69 | | static std::unique_ptr<geom::Geometry> reduce( |
70 | | const geom::Geometry& geom, |
71 | | const geom::PrecisionModel& targetPM, |
72 | | bool isRemoveCollapsed = false); |
73 | | |
74 | | |
75 | | protected: |
76 | | |
77 | | std::unique_ptr<geom::CoordinateSequence> transformCoordinates( |
78 | | const geom::CoordinateSequence* coords, |
79 | | const geom::Geometry* parent) override; |
80 | | |
81 | | std::unique_ptr<geom::Geometry> transformPolygon( |
82 | | const geom::Polygon* geom, |
83 | | const geom::Geometry* parent) override; |
84 | | |
85 | | std::unique_ptr<geom::Geometry> transformMultiPolygon( |
86 | | const geom::MultiPolygon* geom, |
87 | | const geom::Geometry* parent) override; |
88 | | |
89 | | |
90 | | }; |
91 | | |
92 | | } // namespace geos.precision |
93 | | } // namespace geos |
94 | | |
95 | | |