25 #include <QJsonObject> 26 #include <nlohmann/json.hpp> 35 return QStringLiteral(
"MultiPolygon" );
46 auto result = qgis::make_unique< QgsMultiPolygon >();
48 return result.release();
64 QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
67 return elemMultiPolygon;
71 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
73 QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
74 elemPolygonMember.appendChild( geom->asGml2( doc, precision, ns, axisOrder ) );
75 elemMultiPolygon.appendChild( elemPolygonMember );
79 return elemMultiPolygon;
84 QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
87 return elemMultiSurface;
91 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
93 QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
94 elemSurfaceMember.appendChild( geom->asGml3( doc, precision, ns, axisOrder ) );
95 elemMultiSurface.appendChild( elemSurfaceMember );
99 return elemMultiSurface;
104 json polygons( json::array( ) );
107 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
109 json coordinates( json::array( ) );
114 exteriorLineString->points( exteriorPts );
117 std::unique_ptr< QgsLineString > interiorLineString;
122 interiorLineString->points( interiorPts );
125 polygons.push_back( coordinates );
130 {
"type",
"MultiPolygon" },
131 {
"coordinates", polygons }
137 if ( !qgsgeometry_cast<QgsPolygon *>( g ) )
161 if ( !g || !qgsgeometry_cast< QgsPolygon * >( g ) )
191 if (
QgsLineString *lineStringBoundary = qgsgeometry_cast< QgsLineString * >( polygonBoundary ) )
193 multiLine->addGeometry( lineStringBoundary );
195 else if (
QgsMultiLineString *multiLineStringBoundary = qgsgeometry_cast< QgsMultiLineString * >( polygonBoundary ) )
197 for (
int j = 0; j < multiLineStringBoundary->numGeometries(); ++j )
199 multiLine->addGeometry( multiLineStringBoundary->geometryN( j )->clone() );
201 delete multiLineStringBoundary;
205 delete polygonBoundary;
209 if ( multiLine->numGeometries() == 0 )
213 return multiLine.release();
bool isMeasure() const
Returns true if the geometry contains m values.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Multi line string geometry collection.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
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...
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
void clear() override
Clears the geometry, ie reset it to a null geometry.
Multi surface geometry collection.
QgsWkbTypes::Type mWkbType
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
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.
QgsMultiSurface * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsMultiSurface.
bool isEmpty() const override
Returns true if the geometry is empty.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
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.
QString geometryType() const override
Returns a unique string representing the geometry type.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, QgsWkbTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
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.
Abstract base class for all geometries.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
AxisOrder
Axis order for GML generation.
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
bool wktOmitChildType() const override
Returns whether child type names are omitted from Wkt representations of the collection.
QVector< QgsPoint > QgsPointSequence
QVector< QgsAbstractGeometry *> mGeometries
void reserve(int size)
Attempts to allocate memory for at least size geometries.
Multi polygon geometry collection.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Line string geometry type, with support for z-dimension and m-values.
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...
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.