24#include <nlohmann/json.hpp>
33 if ( polygons.empty() )
47 if ( polygons.empty() )
61 return qgsgeometry_cast< QgsPolygon * >(
geometryN( index ) );
66 return qgsgeometry_cast< const QgsPolygon * >(
geometryN( index ) );
71 return QStringLiteral(
"MultiPolygon" );
82 auto result = std::make_unique< QgsMultiPolygon >();
84 return result.release();
100 QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
103 return elemMultiPolygon;
107 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
109 QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
110 elemPolygonMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
111 elemMultiPolygon.appendChild( elemPolygonMember );
115 return elemMultiPolygon;
120 QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral(
"MultiSurface" ) );
123 return elemMultiSurface;
127 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
129 QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral(
"surfaceMember" ) );
130 elemSurfaceMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
131 elemMultiSurface.appendChild( elemSurfaceMember );
135 return elemMultiSurface;
140 json polygons( json::array( ) );
143 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
145 json coordinates( json::array( ) );
150 exteriorLineString->points( exteriorPts );
153 std::unique_ptr< QgsLineString > interiorLineString;
158 interiorLineString->points( interiorPts );
161 polygons.push_back( coordinates );
166 {
"type",
"MultiPolygon" },
167 {
"coordinates", polygons }
173 if ( !qgsgeometry_cast<QgsPolygon *>( g ) )
199 if ( !qgsgeometry_cast<QgsPolygon *>( g ) )
201 qDeleteAll( geometries );
213 if (
is3D() && !g->is3D() )
215 else if ( !
is3D() && g->is3D() )
219 else if ( !
isMeasure() && g->isMeasure() )
230 if ( !g || !qgsgeometry_cast< QgsPolygon * >( g ) )
241 std::unique_ptr< QgsMultiPolygon > res = std::make_unique< QgsMultiPolygon >();
245 res->addGeometry(
mGeometries.at( i )->simplifyByDistance( tolerance ) );
247 return res.release();
271 if (
QgsLineString *lineStringBoundary = qgsgeometry_cast< QgsLineString * >( polygonBoundary ) )
273 multiLine->addGeometry( lineStringBoundary );
275 else if (
QgsMultiLineString *multiLineStringBoundary = qgsgeometry_cast< QgsMultiLineString * >( polygonBoundary ) )
277 for (
int j = 0; j < multiLineStringBoundary->numGeometries(); ++j )
279 multiLine->addGeometry( multiLineStringBoundary->geometryN( j )->clone() );
281 delete multiLineStringBoundary;
285 delete polygonBoundary;
289 if ( multiLine->numGeometries() == 0 )
293 return multiLine.release();
@ MultiPolygon
MultiPolygon.
Abstract base class for all geometries.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
QVector< QgsAbstractGeometry * > mGeometries
void reserve(int size)
Attempts to allocate memory for at least size geometries.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
bool isEmpty() const override
Returns true if the geometry is empty.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
Line string geometry type, with support for z-dimension and m-values.
Multi line string geometry collection.
Multi polygon geometry collection.
bool wktOmitChildType() const override
Returns whether child type names are omitted from Wkt representations of the collection.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
QgsMultiSurface * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsMultiSurface.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
QgsMultiPolygon * simplifyByDistance(double tolerance) const override
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
bool addGeometries(const QVector< QgsAbstractGeometry * > &geometries) final
Adds a list of geometries to the collection, transferring ownership to the collection.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QgsMultiPolygon()
Constructor for an empty multipolygon geometry.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
QgsMultiPolygon * clone() const override
Clones the geometry by performing a deep copy.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QgsMultiPolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Multi surface geometry collection.
QgsMultiSurface()
Constructor for an empty multisurface geometry.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QVector< QgsPoint > QgsPointSequence