26#include <nlohmann/json.hpp>
35 return qgsgeometry_cast< QgsSurface * >(
geometryN( index ) );
40 return qgsgeometry_cast< const QgsSurface * >(
geometryN( index ) );
45 return QStringLiteral(
"MultiSurface" );
56 auto result = std::make_unique< QgsMultiSurface >();
58 return result.release();
75 QStringLiteral(
"Polygon" ) );
81 QDomElement elemMultiPolygon = doc.createElementNS( ns, QStringLiteral(
"MultiPolygon" ) );
84 return elemMultiPolygon;
88 if ( qgsgeometry_cast<const QgsSurface *>( geom ) )
90 std::unique_ptr< QgsPolygon > polygon(
static_cast<const QgsSurface *
>( geom )->surfaceToPolygon() );
92 QDomElement elemPolygonMember = doc.createElementNS( ns, QStringLiteral(
"polygonMember" ) );
93 elemPolygonMember.appendChild( polygon->asGml2( doc,
precision, ns, axisOrder ) );
94 elemMultiPolygon.appendChild( elemPolygonMember );
98 return elemMultiPolygon;
103 QDomElement elemMultiSurface = doc.createElementNS( ns, QStringLiteral(
"MultiSurface" ) );
106 return elemMultiSurface;
110 if ( qgsgeometry_cast<const QgsSurface *>( geom ) )
112 QDomElement elemSurfaceMember = doc.createElementNS( ns, QStringLiteral(
"surfaceMember" ) );
113 elemSurfaceMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
114 elemMultiSurface.appendChild( elemSurfaceMember );
118 return elemMultiSurface;
124 json polygons( json::array( ) );
127 if ( qgsgeometry_cast<const QgsSurface *>( geom ) )
129 json coordinates( json::array( ) );
130 std::unique_ptr< QgsPolygon >polygon(
static_cast<const QgsSurface *
>( geom )->surfaceToPolygon() );
131 std::unique_ptr< QgsLineString > exteriorLineString( polygon->exteriorRing()->curveToLine() );
133 exteriorLineString->points( exteriorPts );
136 std::unique_ptr< QgsLineString > interiorLineString;
137 for (
int i = 0, n = polygon->numInteriorRings(); i < n; ++i )
139 interiorLineString.reset( polygon->interiorRing( i )->curveToLine() );
141 interiorLineString->points( interiorPts );
144 polygons.push_back( coordinates );
149 {
"type",
"MultiPolygon" },
150 {
"coordinates", polygons }
156 if ( !qgsgeometry_cast<QgsSurface *>( g ) )
180 if ( !g || !qgsgeometry_cast< QgsSurface * >( g ) )
191 std::unique_ptr< QgsMultiCurve > multiCurve(
new QgsMultiCurve() );
197 multiCurve->addGeometry( surface->boundary() );
200 if ( multiCurve->numGeometries() == 0 )
204 return multiCurve.release();
@ MultiSurface
MultiSurface.
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 bool dropMValue()=0
Drops any measure values which exist in the geometry.
bool is3D() const SIP_HOLDGIL
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.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
Curve polygon geometry type.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
QVector< QgsAbstractGeometry * > mGeometries
void clear() override
Clears the geometry, ie reset it to a null geometry.
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
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.
Multi curve geometry collection.
Multi surface geometry collection.
QgsMultiSurface() SIP_HOLDGIL
Constructor for an empty multisurface geometry.
QgsSurface * surfaceN(int index)
Returns the surface 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.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
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 fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QgsMultiSurface * clone() const override
Clones the geometry by performing a deep copy.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
QgsMultiSurface * 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...
QgsMultiSurface * toCurveType() const override
Returns the geometry converted to the more generic curve type.
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.
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
QVector< QgsPoint > QgsPointSequence