GEOS 3.16.0dev
GeometryCollection.h
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
32namespace geos {
33namespace geom { // geos::geom
34class Coordinate;
36}
37}
38
39namespace geos {
40namespace geom { // geos::geom
41
51class GEOS_DLL GeometryCollection : public Geometry {
52
53public:
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 {
62 return geometries.begin();
63 };
64
65 const_iterator end() const
66 {
67 return geometries.end();
68 };
69
76 std::unique_ptr<GeometryCollection> clone() const
77 {
78 return std::unique_ptr<GeometryCollection>(cloneImpl());
79 }
80
81 ~GeometryCollection() override = default;
82
83 void setSRID(int) override;
84
98 std::unique_ptr<CoordinateSequence> getCoordinates() const override;
99
100 bool isEmpty() const override;
101
110
112
114
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
129 int getBoundaryDimension() const override;
130
131 std::size_t getNumPoints() const override;
132
133 std::string getGeometryType() const override;
134
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
163 double getArea() const override;
164
166 double getLength() const override;
167
169 std::size_t getNumGeometries() const override;
170
171 std::unique_ptr<GeometryCollection> getCurved(const algorithm::LineToCurveParams& params) {
172 return std::unique_ptr<GeometryCollection>(getCurvedImpl(params));
173 }
174
175 std::unique_ptr<GeometryCollection> getLinearized(const algorithm::CurveToLineParams& params) {
176 return std::unique_ptr<GeometryCollection>(getLinearizedImpl(params));
177 }
178
180 const Geometry* getGeometryN(std::size_t n) const override;
181
182 bool hasCurvedTypes() const override;
183
191 std::vector<std::unique_ptr<Geometry>> releaseGeometries();
192
200 std::unique_ptr<GeometryCollection> reverse() const { return std::unique_ptr<GeometryCollection>(reverseImpl()); }
201
202 const Envelope* getEnvelopeInternal() const override {
203 if (envelope.isNull()) {
204 envelope = computeEnvelopeInternal();
205 }
206 return &envelope;
207 }
208
209protected:
210
211 struct CollectionFlags {
212 bool flagsCalculated;
213 bool hasPoints;
214 bool hasLines;
215 bool hasPolygons;
216 bool hasM;
217 bool hasZ;
218 bool hasCurves;
219 bool hasCurvedTypes;
220 };
221
222 GeometryCollection(const GeometryCollection& gc);
223 GeometryCollection& operator=(const GeometryCollection& gc);
224
242 GeometryCollection(std::vector<std::unique_ptr<Geometry>> && newGeoms, const GeometryFactory& newFactory);
243
245 template<typename T>
246 GeometryCollection(std::vector<std::unique_ptr<T>> && newGeoms, const GeometryFactory& newFactory) :
247 GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {}
248
249 GeometryCollection* cloneImpl() const override { return new GeometryCollection(*this); }
250
251 GeometryCollection* reverseImpl() const override;
252
253 GeometryCollection* getLinearizedImpl(const algorithm::CurveToLineParams&) const override;
254
255 GeometryCollection* getCurvedImpl(const algorithm::LineToCurveParams&) const override;
256
257 int
258 getSortIndex() const override
259 {
260 return SORTINDEX_GEOMETRYCOLLECTION;
261 };
262
263 std::vector<std::unique_ptr<Geometry>> geometries;
264 mutable CollectionFlags flags;
265 mutable Envelope envelope;
266
267 Envelope computeEnvelopeInternal() const;
268
269 void geometryChangedAction() override {
270 envelope.setToNull();
271 flags.flagsCalculated = false;
272 }
273
274 int compareToSameClass(const Geometry* gc) const override;
275
276 bool hasCurvedComponents() const override;
277
278 void setFlags() const;
279
280};
281
282} // namespace geos::geom
283} // namespace geos
284
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition CoordinateFilter.h:43
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition CoordinateSequenceFilter.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
DimensionType
Definition Dimension.h:29
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
void setSRID(int) override
Sets the ID of the Spatial Reference System used by the Geometry.
bool isDimensionStrict(Dimension::DimensionType d) const override
Checks whether this Geometry consists only of components having dimension d.
bool hasCurvedTypes() const override
GeometryCollection(std::vector< std::unique_ptr< T > > &&newGeoms, const GeometryFactory &newFactory)
Convenience constructor to build a GeometryCollection from vector of Geometry subclass pointers.
Definition GeometryCollection.h:246
std::string getGeometryType() const override
Return a string representation of this Geometry type.
GeometryCollection * cloneImpl() const override
Make a deep-copy of this Geometry.
Definition GeometryCollection.h:249
const Geometry * getGeometryN(std::size_t n) const override
Returns a pointer to the nth Geometry in this collection.
uint8_t getCoordinateDimension() const override
Returns coordinate dimension.
bool equalsIdentical(const Geometry *other) const override
Returns true if the two geometries are of the same type and their vertices corresponding by index are...
std::unique_ptr< GeometryCollection > clone() const
Definition GeometryCollection.h:76
void apply_ro(CoordinateSequenceFilter &filter) const override
bool hasCurvedComponents() const override
Returns whether the Geometry contains arcs.
void geometryChangedAction() override
Notifies this Geometry that its Coordinates have been changed by an external party.
Definition GeometryCollection.h:269
GeometryTypeId getGeometryTypeId() const override
Return an integer representation of this Geometry type.
std::vector< std::unique_ptr< Geometry > > releaseGeometries()
Take ownership of the sub-geometries managed by this GeometryCollection. After releasing the sub-geom...
std::unique_ptr< CoordinateSequence > getCoordinates() const override
Collects all coordinates of all subgeometries into a CoordinateSequence.
double getArea() const override
Returns the total area of this collection.
std::size_t getNumPoints() const override
Returns the count of this Geometrys vertices.
bool hasDimension(Dimension::DimensionType d) const override
Checks whether any component of this geometry has dimension d.
const CoordinateXY * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
bool isEmpty() const override
Returns whether or not the set of points in this Geometry is empty.
Dimension::DimensionType getDimension() const override
Returns the maximum dimension of geometries in this collection (0=point, 1=line, 2=surface).
int getBoundaryDimension() const override
Returns the maximum boundary dimension of geometries in this collection.
double getLength() const override
Returns the total length of this collection.
bool equalsExact(const Geometry *other, double tolerance=0) const override
Returns true iff the two Geometrys are of the same type and their vertices corresponding by index are...
GeometryCollection * reverseImpl() const override
Make a geometry with coordinates in reverse order.
std::unique_ptr< Geometry > getBoundary() const override
Returns the boundary, or an empty geometry of appropriate dimension if this Geometry is empty.
std::size_t getNumGeometries() const override
Returns the number of geometries in this collection.
GeometryCollection(std::vector< std::unique_ptr< Geometry > > &&newGeoms, const GeometryFactory &newFactory)
Construct a GeometryCollection with the given GeometryFactory. Will keep a reference to the factory,...
const Envelope * getEnvelopeInternal() const override
Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry ...
Definition GeometryCollection.h:202
std::unique_ptr< GeometryCollection > reverse() const
Definition GeometryCollection.h:200
void apply_rw(CoordinateSequenceFilter &filter) override
Definition GeometryComponentFilter.h:41
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition GeometryFilter.h:45
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:201
Definition Angle.h:26
GeometryTypeId
Geometry types.
Definition Geometry.h:78
Basic namespace for all GEOS functionalities.
Definition geos.h:38