23 #include <QJsonObject>
24 #include <QRegularExpression>
25 #include <nlohmann/json.hpp>
34 return qgsgeometry_cast< QgsPoint * >(
geometryN( index ) );
39 return qgsgeometry_cast< const QgsPoint * >(
geometryN( index ) );
44 return QStringLiteral(
"MultiPoint" );
49 auto result = std::make_unique< QgsMultiPoint >();
51 return result.release();
66 QString collectionWkt( wkt );
68 const thread_local QRegularExpression regex( QStringLiteral(
"^\\s*MultiPoint\\s*[ZM]*\\s*\\(\\s*[-\\d]" ), QRegularExpression::CaseInsensitiveOption );
69 const QRegularExpressionMatch match = regex.match( collectionWkt );
70 if ( match.hasMatch() )
73 collectionWkt.replace(
'(', QLatin1String(
"((" ) ).replace(
')', QLatin1String(
"))" ) ).replace(
',', QLatin1String(
"),(" ) );
87 QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral(
"MultiPoint" ) );
90 return elemMultiPoint;
94 if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
96 QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral(
"pointMember" ) );
97 elemPointMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
98 elemMultiPoint.appendChild( elemPointMember );
102 return elemMultiPoint;
107 QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral(
"MultiPoint" ) );
110 return elemMultiPoint;
114 if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
116 QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral(
"pointMember" ) );
117 elemPointMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
118 elemMultiPoint.appendChild( elemPointMember );
122 return elemMultiPoint;
129 {
"type",
"MultiPoint" },
130 {
"coordinates", json::array() },
151 if ( !qgsgeometry_cast<QgsPoint *>( g ) )
190 if (
id.part < 0 || id.part >=
mGeometries.count() ||
id.vertex != 0 ||
id.ring != 0 )
211 if ( const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( part ) )
213 if ( !filter( *point ) )
228 } ), mGeometries.end() );
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.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
QgsWkbTypes::Type mWkbType
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, QgsWkbTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
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.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
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.
Multi point geometry collection.
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.
void clear() override
Clears the geometry, ie reset it to a null 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.
bool wktOmitChildType() const override
Returns whether child type names are omitted from Wkt representations of the collection.
int nCoordinates() const override SIP_HOLDGIL
Returns the number of nodes contained in the geometry.
QgsMultiPoint() SIP_HOLDGIL
Constructor for an empty multipoint geometry.
QgsPoint * pointN(int index)
Returns the point with the specified index.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
bool isValid(QString &error, int flags=0) const override SIP_HOLDGIL
Checks validity of the geometry, and returns true if the geometry is valid.
QgsMultiPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
QString geometryType() const override
Returns a unique string representing the geometry type.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
QgsMultiPoint * clone() const override
Clones the geometry by performing a deep copy.
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.
QgsMultiPoint * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Point geometry type, with support for z-dimension and m-values.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Utility class for identifying a unique vertex within a geometry.