16 #ifndef QGSMULTIPOINT_H
17 #define QGSMULTIPOINT_H
19 #include "qgis_core.h"
77 if ( !PySequence_Check( a0 ) )
79 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"A sequence of QgsPoint, QgsPointXY or array of floats is expected" ).toUtf8().constData() );
85 const int size = PySequence_Size( a0 );
86 QVector< QgsPoint * > pointList;
87 pointList.reserve( size );
90 for (
int i = 0; i < size; ++i )
92 PyObject *value = PySequence_GetItem( a0, i );
95 qDeleteAll( pointList );
97 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
102 if ( PySequence_Check( value ) )
104 const int elementSize = PySequence_Size( value );
105 if ( elementSize < 2 || elementSize > 4 )
107 qDeleteAll( pointList );
110 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid sequence size at index %1. Expected an array of 2-4 float values, got %2." ).arg( i ).arg( elementSize ).toUtf8().constData() );
118 PyObject *element = PySequence_GetItem( value, 0 );
121 qDeleteAll( pointList );
123 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
129 const double x = PyFloat_AsDouble( element );
130 Py_DECREF( element );
131 if ( PyErr_Occurred() )
133 qDeleteAll( pointList );
140 element = PySequence_GetItem( value, 1 );
143 qDeleteAll( pointList );
146 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
152 const double y = PyFloat_AsDouble( element );
153 Py_DECREF( element );
154 if ( PyErr_Occurred() )
156 qDeleteAll( pointList );
163 std::unique_ptr< QgsPoint > point = std::make_unique< QgsPoint >( x, y );
164 if ( elementSize > 2 )
166 element = PySequence_GetItem( value, 2 );
169 qDeleteAll( pointList );
172 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
178 const double z = PyFloat_AsDouble( element );
179 Py_DECREF( element );
180 if ( PyErr_Occurred() )
182 qDeleteAll( pointList );
188 point->addZValue( z );
190 if ( elementSize > 3 )
192 element = PySequence_GetItem( value, 3 );
195 qDeleteAll( pointList );
198 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
204 const double m = PyFloat_AsDouble( element );
205 Py_DECREF( element );
206 if ( PyErr_Occurred() )
208 qDeleteAll( pointList );
214 point->addMValue( m );
216 pointList.append( point.release() );
221 qDeleteAll( pointList );
229 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
232 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
235 pointList.append(
new QgsPoint( p->
x(), p->
y() ) );
237 sipReleaseType( p, sipType_QgsPointXY, state );
239 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
242 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
245 pointList.append( p->
clone() );
247 sipReleaseType( p, sipType_QgsPoint, state );
258 qDeleteAll( pointList );
261 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats." ).arg( i ) .toUtf8().constData() );
283 QgsMultiPoint(
const QVector<double> &x,
const QVector<double> &y,
284 const QVector<double> &z = QVector<double>(),
285 const QVector<double> &m = QVector<double>() )
SIP_HOLDGIL;
306 if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
308 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
313 return sipConvertFromType( sipCpp->pointN( a0 ), sipType_QgsPoint, NULL );
327 const QgsPoint *pointN(
int index )
const;
333 bool fromWkt(
const QString &wkt )
override;
334 void clear()
override;
366 SIP_PYOBJECT __repr__();
368 QString wkt = sipCpp->asWkt();
369 if ( wkt.length() > 1000 )
370 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
371 QString
str = QStringLiteral(
"<QgsMultiPoint: %1>" ).arg( wkt );
372 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
Abstract base class for all geometries.
AxisOrder
Axis order for GML generation.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QgsGeometryCollection * toCurveType() const override
Returns the geometry converted to the more generic curve type.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
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...
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.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
QgsGeometryCollection * clone() const override
Clones the geometry by performing a deep copy.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
virtual bool wktOmitChildType() const
Returns whether child type names are omitted from Wkt representations of the collection.
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
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.
Multi point geometry collection.
static const QgsMultiPoint * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsLineString.
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 flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_TYPEHINT(type)
Utility class for identifying a unique vertex within a geometry.