QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
25 #include <QJsonObject>
26 #include <nlohmann/json.hpp>
35 return qgsgeometry_cast< QgsPolygon * >(
geometryN( index ) );
40 return qgsgeometry_cast< const QgsPolygon * >(
geometryN( index ) );
45 return QStringLiteral(
"MultiPolygon" );
56 auto result = qgis::make_unique< QgsMultiPolygon >();
58 return result.release();
74 QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
77 return elemMultiPolygon;
81 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
83 QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
84 elemPolygonMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
85 elemMultiPolygon.appendChild( elemPolygonMember );
89 return elemMultiPolygon;
94 QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
97 return elemMultiSurface;
101 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
103 QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
104 elemSurfaceMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
105 elemMultiSurface.appendChild( elemSurfaceMember );
109 return elemMultiSurface;
114 json polygons( json::array( ) );
117 if ( qgsgeometry_cast<const QgsPolygon *>( geom ) )
119 json coordinates( json::array( ) );
124 exteriorLineString->points( exteriorPts );
127 std::unique_ptr< QgsLineString > interiorLineString;
132 interiorLineString->points( interiorPts );
135 polygons.push_back( coordinates );
140 {
"type",
"MultiPolygon" },
141 {
"coordinates", polygons }
147 if ( !qgsgeometry_cast<QgsPolygon *>( g ) )
171 if ( !g || !qgsgeometry_cast< QgsPolygon * >( g ) )
201 if (
QgsLineString *lineStringBoundary = qgsgeometry_cast< QgsLineString * >( polygonBoundary ) )
203 multiLine->addGeometry( lineStringBoundary );
205 else if (
QgsMultiLineString *multiLineStringBoundary = qgsgeometry_cast< QgsMultiLineString * >( polygonBoundary ) )
207 for (
int j = 0; j < multiLineStringBoundary->numGeometries(); ++j )
209 multiLine->addGeometry( multiLineStringBoundary->geometryN( j )->clone() );
211 delete multiLineStringBoundary;
215 delete polygonBoundary;
219 if ( multiLine->numGeometries() == 0 )
223 return multiLine.release();
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
QgsMultiPolygon * clone() const override
Clones the geometry by performing a deep copy.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Multi line string geometry collection.
QVector< QgsAbstractGeometry * > mGeometries
QgsWkbTypes::Type mWkbType
Multi surface geometry collection.
Line string geometry type, with support for z-dimension and m-values.
bool wktOmitChildType() const override
Returns whether child type names are omitted from Wkt representations of the collection.
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
AxisOrder
Axis order for GML generation.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
QgsMultiPolygon() SIP_HOLDGIL
Constructor for an empty multipolygon geometry.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
Multi polygon geometry collection.
void clear() override
Clears the geometry, ie reset it to a null geometry.
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
QgsMultiPolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Abstract base class for all geometries.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
QVector< QgsPoint > QgsPointSequence
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
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.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, QgsWkbTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
void reserve(int size) SIP_HOLDGIL
Attempts to allocate memory for at least size geometries.
QgsMultiSurface() SIP_HOLDGIL
Constructor for an empty multisurface geometry.
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.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
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.