/src/geos/include/geos/geom/GeometryCollection.h
Line | Count | Source (jump to first uncovered line) |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2001-2002 Vivid Solutions Inc. |
7 | | * Copyright (C) 2005 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: geom/GeometryCollection.java rev. 1.41 |
17 | | * |
18 | | **********************************************************************/ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <geos/export.h> |
23 | | #include <geos/geom/Geometry.h> // for inheritance |
24 | | #include <geos/geom/Envelope.h> // for proper use of unique_ptr<> |
25 | | #include <geos/geom/Dimension.h> // for Dimension::DimensionType |
26 | | |
27 | | #include <string> |
28 | | #include <vector> |
29 | | #include <memory> // for unique_ptr |
30 | | |
31 | | // Forward declarations |
32 | | namespace geos { |
33 | | namespace geom { // geos::geom |
34 | | class Coordinate; |
35 | | class CoordinateSequenceFilter; |
36 | | } |
37 | | } |
38 | | |
39 | | namespace geos { |
40 | | namespace geom { // geos::geom |
41 | | |
42 | | /** |
43 | | * \class GeometryCollection geom.h geos.h |
44 | | * |
45 | | * \brief Represents a collection of heterogeneous Geometry objects. |
46 | | * |
47 | | * Collections of Geometry of the same type are |
48 | | * represented by GeometryCollection subclasses MultiPoint, |
49 | | * MultiLineString, MultiPolygon. |
50 | | */ |
51 | | class GEOS_DLL GeometryCollection : public Geometry { |
52 | | |
53 | | public: |
54 | | friend class GeometryFactory; |
55 | | |
56 | | typedef std::vector<std::unique_ptr<Geometry>>::const_iterator const_iterator; |
57 | | |
58 | | typedef std::vector<std::unique_ptr<Geometry>>::iterator iterator; |
59 | | |
60 | | const_iterator begin() const |
61 | 54.2k | { |
62 | 54.2k | return geometries.begin(); |
63 | 54.2k | }; |
64 | | |
65 | | const_iterator end() const |
66 | 54.2k | { |
67 | 54.2k | return geometries.end(); |
68 | 54.2k | }; |
69 | | |
70 | | /** |
71 | | * Creates and returns a full copy of this GeometryCollection object. |
72 | | * (including all coordinates contained by it). |
73 | | * |
74 | | * @return a clone of this instance |
75 | | */ |
76 | | std::unique_ptr<GeometryCollection> clone() const |
77 | 0 | { |
78 | 0 | return std::unique_ptr<GeometryCollection>(cloneImpl()); |
79 | 0 | } |
80 | | |
81 | 289k | ~GeometryCollection() override = default; |
82 | | |
83 | | void setSRID(int) override; |
84 | | |
85 | | /** |
86 | | * \brief |
87 | | * Collects all coordinates of all subgeometries into a |
88 | | * CoordinateSequence. |
89 | | * |
90 | | * Note that the returned coordinates are copies, so |
91 | | * you want be able to use them to modify the geometries |
92 | | * in place. Also you'll need to delete the CoordinateSequence |
93 | | * when finished using it. |
94 | | * |
95 | | * @return the collected coordinates |
96 | | * |
97 | | */ |
98 | | std::unique_ptr<CoordinateSequence> getCoordinates() const override; |
99 | | |
100 | | bool isEmpty() const override; |
101 | | |
102 | | /** |
103 | | * \brief |
104 | | * Returns the maximum dimension of geometries in this collection |
105 | | * (0=point, 1=line, 2=surface) |
106 | | * |
107 | | * @see Dimension::DimensionType |
108 | | */ |
109 | | Dimension::DimensionType getDimension() const override; |
110 | | |
111 | | bool hasDimension(Dimension::DimensionType d) const override; |
112 | | |
113 | | bool isDimensionStrict(Dimension::DimensionType d) const override; |
114 | | |
115 | | /// Returns coordinate dimension. |
116 | | uint8_t getCoordinateDimension() const override; |
117 | | |
118 | | bool hasM() const override; |
119 | | |
120 | | bool hasZ() const override; |
121 | | |
122 | | std::unique_ptr<Geometry> getBoundary() const override; |
123 | | |
124 | | /** |
125 | | * \brief |
126 | | * Returns the maximum boundary dimension of geometries in |
127 | | * this collection. |
128 | | */ |
129 | | int getBoundaryDimension() const override; |
130 | | |
131 | | std::size_t getNumPoints() const override; |
132 | | |
133 | | std::string getGeometryType() const override; |
134 | | |
135 | | GeometryTypeId getGeometryTypeId() const override; |
136 | | |
137 | | bool equalsExact(const Geometry* other, |
138 | | double tolerance = 0) const override; |
139 | | |
140 | | bool equalsIdentical(const Geometry* other) const override; |
141 | | |
142 | | void apply_ro(CoordinateFilter* filter) const override; |
143 | | |
144 | | void apply_rw(const CoordinateFilter* filter) override; |
145 | | |
146 | | void apply_ro(GeometryFilter* filter) const override; |
147 | | |
148 | | void apply_rw(GeometryFilter* filter) override; |
149 | | |
150 | | void apply_ro(GeometryComponentFilter* filter) const override; |
151 | | |
152 | | void apply_rw(GeometryComponentFilter* filter) override; |
153 | | |
154 | | void apply_rw(CoordinateSequenceFilter& filter) override; |
155 | | |
156 | | void apply_ro(CoordinateSequenceFilter& filter) const override; |
157 | | |
158 | | void normalize() override; |
159 | | |
160 | | const CoordinateXY* getCoordinate() const override; |
161 | | |
162 | | /// Returns the total area of this collection |
163 | | double getArea() const override; |
164 | | |
165 | | /// Returns the total length of this collection |
166 | | double getLength() const override; |
167 | | |
168 | | /// Returns the number of geometries in this collection |
169 | | std::size_t getNumGeometries() const override; |
170 | | |
171 | | /// Returns a pointer to the nth Geometry in this collection |
172 | | const Geometry* getGeometryN(std::size_t n) const override; |
173 | | |
174 | | /** |
175 | | * \brief |
176 | | * Take ownership of the sub-geometries managed by this GeometryCollection. |
177 | | * After releasing the sub-geometries, the collection should be considered |
178 | | * in a moved-from state and should not be accessed. |
179 | | * @return vector of sub-geometries |
180 | | */ |
181 | | std::vector<std::unique_ptr<Geometry>> releaseGeometries(); |
182 | | |
183 | | /** |
184 | | * Creates a GeometryCollection with |
185 | | * every component reversed. |
186 | | * The order of the components in the collection are not reversed. |
187 | | * |
188 | | * @return a GeometryCollection in the reverse order |
189 | | */ |
190 | 0 | std::unique_ptr<GeometryCollection> reverse() const { return std::unique_ptr<GeometryCollection>(reverseImpl()); } |
191 | | |
192 | 158k | const Envelope* getEnvelopeInternal() const override { |
193 | 158k | if (envelope.isNull()) { |
194 | 13.7k | envelope = computeEnvelopeInternal(); |
195 | 13.7k | } |
196 | 158k | return &envelope; |
197 | 158k | } |
198 | | |
199 | | protected: |
200 | | |
201 | | struct CollectionFlags { |
202 | | bool flagsCalculated; |
203 | | bool hasPoints; |
204 | | bool hasLines; |
205 | | bool hasPolygons; |
206 | | bool hasM; |
207 | | bool hasZ; |
208 | | bool hasCurves; |
209 | | }; |
210 | | |
211 | | GeometryCollection(const GeometryCollection& gc); |
212 | | GeometryCollection& operator=(const GeometryCollection& gc); |
213 | | |
214 | | /** \brief |
215 | | * Construct a GeometryCollection with the given GeometryFactory. |
216 | | * Will keep a reference to the factory, so don't |
217 | | * delete it until al Geometry objects referring to |
218 | | * it are deleted. |
219 | | * Will take ownership of the Geometry vector. |
220 | | * |
221 | | * @param newGeoms |
222 | | * The <code>Geometry</code>s for this |
223 | | * <code>GeometryCollection</code>, |
224 | | * or <code>null</code> or an empty array to |
225 | | * create the empty geometry. |
226 | | * Elements may be empty <code>Geometry</code>s, |
227 | | * but not <code>null</code>s. |
228 | | * |
229 | | * @param newFactory the GeometryFactory used to create this geometry |
230 | | */ |
231 | | GeometryCollection(std::vector<std::unique_ptr<Geometry>> && newGeoms, const GeometryFactory& newFactory); |
232 | | |
233 | | /// Convenience constructor to build a GeometryCollection from vector of Geometry subclass pointers |
234 | | template<typename T> |
235 | | GeometryCollection(std::vector<std::unique_ptr<T>> && newGeoms, const GeometryFactory& newFactory) : |
236 | 9.37k | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} geos::geom::GeometryCollection::GeometryCollection<geos::geom::Curve>(std::__1::vector<std::__1::unique_ptr<geos::geom::Curve, std::__1::default_delete<geos::geom::Curve> >, std::__1::allocator<std::__1::unique_ptr<geos::geom::Curve, std::__1::default_delete<geos::geom::Curve> > > >&&, geos::geom::GeometryFactory const&) Line | Count | Source | 236 | 163 | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} |
geos::geom::GeometryCollection::GeometryCollection<geos::geom::LineString>(std::__1::vector<std::__1::unique_ptr<geos::geom::LineString, std::__1::default_delete<geos::geom::LineString> >, std::__1::allocator<std::__1::unique_ptr<geos::geom::LineString, std::__1::default_delete<geos::geom::LineString> > > >&&, geos::geom::GeometryFactory const&) Line | Count | Source | 236 | 441 | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} |
geos::geom::GeometryCollection::GeometryCollection<geos::geom::Point>(std::__1::vector<std::__1::unique_ptr<geos::geom::Point, std::__1::default_delete<geos::geom::Point> >, std::__1::allocator<std::__1::unique_ptr<geos::geom::Point, std::__1::default_delete<geos::geom::Point> > > >&&, geos::geom::GeometryFactory const&) Line | Count | Source | 236 | 6.91k | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} |
geos::geom::GeometryCollection::GeometryCollection<geos::geom::Polygon>(std::__1::vector<std::__1::unique_ptr<geos::geom::Polygon, std::__1::default_delete<geos::geom::Polygon> >, std::__1::allocator<std::__1::unique_ptr<geos::geom::Polygon, std::__1::default_delete<geos::geom::Polygon> > > >&&, geos::geom::GeometryFactory const&) Line | Count | Source | 236 | 864 | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} |
geos::geom::GeometryCollection::GeometryCollection<geos::geom::Surface>(std::__1::vector<std::__1::unique_ptr<geos::geom::Surface, std::__1::default_delete<geos::geom::Surface> >, std::__1::allocator<std::__1::unique_ptr<geos::geom::Surface, std::__1::default_delete<geos::geom::Surface> > > >&&, geos::geom::GeometryFactory const&) Line | Count | Source | 236 | 996 | GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {} |
|
237 | | |
238 | 15.2k | GeometryCollection* cloneImpl() const override { return new GeometryCollection(*this); } |
239 | | |
240 | | GeometryCollection* reverseImpl() const override; |
241 | | |
242 | | int |
243 | | getSortIndex() const override |
244 | 0 | { |
245 | 0 | return SORTINDEX_GEOMETRYCOLLECTION; |
246 | 0 | }; |
247 | | |
248 | | std::vector<std::unique_ptr<Geometry>> geometries; |
249 | | mutable CollectionFlags flags; |
250 | | mutable Envelope envelope; |
251 | | |
252 | | Envelope computeEnvelopeInternal() const; |
253 | | |
254 | 31.3k | void geometryChangedAction() override { |
255 | 31.3k | envelope.setToNull(); |
256 | 31.3k | } |
257 | | |
258 | | int compareToSameClass(const Geometry* gc) const override; |
259 | | |
260 | | bool hasCurvedComponents() const override; |
261 | | |
262 | | void setFlags() const; |
263 | | |
264 | | }; |
265 | | |
266 | | } // namespace geos::geom |
267 | | } // namespace geos |
268 | | |