GEOS 3.11.1
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;
35class CoordinateArraySequence;
36class CoordinateSequenceFilter;
37}
38}
39
40namespace geos {
41namespace geom { // geos::geom
42
52class GEOS_DLL GeometryCollection : public Geometry {
53
54public:
55 friend class GeometryFactory;
56
57 typedef std::vector<std::unique_ptr<Geometry>>::const_iterator const_iterator;
58
59 typedef std::vector<std::unique_ptr<Geometry>>::iterator iterator;
60
61 const_iterator begin() const
62 {
63 return geometries.begin();
64 };
65
66 const_iterator end() const
67 {
68 return geometries.end();
69 };
70
77 std::unique_ptr<GeometryCollection> clone() const
78 {
79 return std::unique_ptr<GeometryCollection>(cloneImpl());
80 }
81
82 ~GeometryCollection() override = default;
83
84 void setSRID(int) override;
85
99 std::unique_ptr<CoordinateSequence> getCoordinates() const override;
100
101 bool isEmpty() const override;
102
111
113
115 uint8_t getCoordinateDimension() const override;
116
117 std::unique_ptr<Geometry> getBoundary() const override;
118
124 int getBoundaryDimension() const override;
125
126 std::size_t getNumPoints() const override;
127
128 std::string getGeometryType() const override;
129
131
132 bool equalsExact(const Geometry* other,
133 double tolerance = 0) const override;
134
135 void apply_ro(CoordinateFilter* filter) const override;
136
137 void apply_rw(const CoordinateFilter* filter) override;
138
139 void apply_ro(GeometryFilter* filter) const override;
140
141 void apply_rw(GeometryFilter* filter) override;
142
143 void apply_ro(GeometryComponentFilter* filter) const override;
144
145 void apply_rw(GeometryComponentFilter* filter) override;
146
147 void apply_rw(CoordinateSequenceFilter& filter) override;
148
149 void apply_ro(CoordinateSequenceFilter& filter) const override;
150
151 void normalize() override;
152
153 const Coordinate* getCoordinate() const override;
154
156 double getArea() const override;
157
159 double getLength() const override;
160
162 std::size_t getNumGeometries() const override;
163
165 const Geometry* getGeometryN(std::size_t n) const override;
166
174 std::vector<std::unique_ptr<Geometry>> releaseGeometries();
175
183 std::unique_ptr<GeometryCollection> reverse() const { return std::unique_ptr<GeometryCollection>(reverseImpl()); }
184
185protected:
186
188
213 GeometryCollection(std::vector<Geometry*>* newGeoms, const GeometryFactory* newFactory);
214
215 GeometryCollection(std::vector<std::unique_ptr<Geometry>> && newGeoms, const GeometryFactory& newFactory);
216
218 template<typename T>
219 GeometryCollection(std::vector<std::unique_ptr<T>> && newGeoms, const GeometryFactory& newFactory) :
220 GeometryCollection(toGeometryArray(std::move(newGeoms)), newFactory) {}
221
222 GeometryCollection* cloneImpl() const override { return new GeometryCollection(*this); }
223
225
226 int
227 getSortIndex() const override
228 {
229 return SORTINDEX_GEOMETRYCOLLECTION;
230 };
231
232 std::vector<std::unique_ptr<Geometry>> geometries;
233
234 Envelope::Ptr computeEnvelopeInternal() const override;
235
236 int compareToSameClass(const Geometry* gc) const override;
237
238};
239
240} // namespace geos::geom
241} // namespace geos
242
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:41
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:55
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
DimensionType
Definition: Dimension.h:29
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:52
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.
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:219
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:222
const Coordinate * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
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.
GeometryCollection(std::vector< Geometry * > *newGeoms, const GeometryFactory *newFactory)
Construct a GeometryCollection with the given GeometryFactory. Will keep a reference to the factory,...
std::unique_ptr< GeometryCollection > clone() const
Definition: GeometryCollection.h:77
void apply_ro(CoordinateSequenceFilter &filter) const override
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 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.
std::unique_ptr< GeometryCollection > reverse() const
Definition: GeometryCollection.h:183
void apply_rw(CoordinateSequenceFilter &filter) override
Definition: GeometryComponentFilter.h:41
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
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:186
GeometryTypeId
Geometry types.
Definition: Geometry.h:73
Basic namespace for all GEOS functionalities.
Definition: geos.h:39