24#include <QRegularExpression>
25#include <nlohmann/json.hpp>
34 if ( points.isEmpty() )
42 const int pointCount = points.size();
45 const QgsPoint *pointIn = points.data();
46 for (
int i = 0; i < pointCount; ++i, ++pointIn )
54 if ( points.isEmpty() )
62 const int pointCount = points.size();
65 for (
int i = 0; i < pointCount; ++i )
74 const int pointCount = points.size();
78 for (
int i = 0; i < pointCount; ++i, ++pointIn )
87 const int pointCount = std::min( x.size(), y.size() );
90 const double *xIn = x.data();
91 const double *yIn = y.data();
92 const double *zIn =
nullptr;
93 const double *mIn =
nullptr;
94 if ( !z.isEmpty() && z.count() >= pointCount )
99 if ( !m.isEmpty() && m.count() >= pointCount )
105 for (
int i = 0; i < pointCount; ++i )
107 mGeometries[ i ] =
new QgsPoint( *xIn++, *yIn++, zIn ? *zIn++ : std::numeric_limits< double >::quiet_NaN(), mIn ? *mIn++ : std::numeric_limits< double >::quiet_NaN() );
113 return qgsgeometry_cast< QgsPoint * >(
geometryN( index ) );
118 return qgsgeometry_cast< const QgsPoint * >(
geometryN( index ) );
123 return QStringLiteral(
"MultiPoint" );
128 auto result = std::make_unique< QgsMultiPoint >();
130 return result.release();
145 QString collectionWkt( wkt );
147 const thread_local QRegularExpression regex( QStringLiteral(
"^\\s*MultiPoint\\s*[ZM]*\\s*\\(\\s*[-\\d]" ), QRegularExpression::CaseInsensitiveOption );
148 const QRegularExpressionMatch match = regex.match( collectionWkt );
149 if ( match.hasMatch() )
152 collectionWkt.replace(
'(', QLatin1String(
"((" ) ).replace(
')', QLatin1String(
"))" ) ).replace(
',', QLatin1String(
"),(" ) );
166 QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral(
"MultiPoint" ) );
169 return elemMultiPoint;
173 if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
175 QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral(
"pointMember" ) );
176 elemPointMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
177 elemMultiPoint.appendChild( elemPointMember );
181 return elemMultiPoint;
186 QDomElement elemMultiPoint = doc.createElementNS( ns, QStringLiteral(
"MultiPoint" ) );
189 return elemMultiPoint;
193 if ( qgsgeometry_cast<const QgsPoint *>( geom ) )
195 QDomElement elemPointMember = doc.createElementNS( ns, QStringLiteral(
"pointMember" ) );
196 elemPointMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
197 elemMultiPoint.appendChild( elemPointMember );
201 return elemMultiPoint;
208 {
"type",
"MultiPoint" },
209 {
"coordinates", json::array() },
230 if ( !qgsgeometry_cast<QgsPoint *>( g ) )
255 if ( !qgsgeometry_cast<QgsPoint *>( g ) )
257 qDeleteAll( geometries );
269 if (
is3D() && !g->is3D() )
271 else if ( !
is3D() && g->is3D() )
275 else if ( !
isMeasure() && g->isMeasure() )
302 if (
id.part < 0 || id.part >=
mGeometries.count() ||
id.vertex != 0 ||
id.ring != 0 )
328 if ( const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( part ) )
330 if ( !filter( *point ) )
345 } ), mGeometries.end() );
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiPointZ
MultiPointZ.
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 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.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
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.
QVector< QgsAbstractGeometry * > mGeometries
void clear() override
Clears the geometry, ie reset it to a null geometry.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
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.
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.
QgsMultiPoint * simplifyByDistance(double tolerance) const override
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
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.
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...
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
bool addGeometries(const QVector< QgsAbstractGeometry * > &geometries) final
Adds a list of geometries to the collection, transferring ownership to the collection.
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.
QgsMultiPoint()
Constructor for an empty multipoint geometry.
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.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
static Qgis::WkbType zmType(Qgis::WkbType type, bool hasZ, bool hasM)
Returns the modified input geometry type according to hasZ / hasM.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type)
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.