78 if ( !PySequence_Check( a0 ) )
80 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"A sequence of QgsPoint, QgsPointXY or array of floats is expected" ).toUtf8().constData() );
86 const int size = PySequence_Size( a0 );
87 QVector< QgsPoint * > pointList;
88 pointList.reserve( size );
91 for (
int i = 0; i < size; ++i )
93 PyObject *value = PySequence_GetItem( a0, i );
96 qDeleteAll( pointList );
98 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
103 if ( PySequence_Check( value ) )
105 const int elementSize = PySequence_Size( value );
106 if ( elementSize < 2 || elementSize > 4 )
108 qDeleteAll( pointList );
111 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() );
119 PyObject *element = PySequence_GetItem( value, 0 );
122 qDeleteAll( pointList );
124 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
130 const double x = PyFloat_AsDouble( element );
131 Py_DECREF( element );
132 if ( PyErr_Occurred() )
134 qDeleteAll( pointList );
141 element = PySequence_GetItem( value, 1 );
144 qDeleteAll( pointList );
147 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
153 const double y = PyFloat_AsDouble( element );
154 Py_DECREF( element );
155 if ( PyErr_Occurred() )
157 qDeleteAll( pointList );
164 std::unique_ptr< QgsPoint > point = std::make_unique< QgsPoint >( x, y );
165 if ( elementSize > 2 )
167 element = PySequence_GetItem( value, 2 );
170 qDeleteAll( pointList );
173 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
179 const double z = PyFloat_AsDouble( element );
180 Py_DECREF( element );
181 if ( PyErr_Occurred() )
183 qDeleteAll( pointList );
189 point->addZValue( z );
191 if ( elementSize > 3 )
193 element = PySequence_GetItem( value, 3 );
196 qDeleteAll( pointList );
199 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1." ).arg( i ) .toUtf8().constData() );
205 const double m = PyFloat_AsDouble( element );
206 Py_DECREF( element );
207 if ( PyErr_Occurred() )
209 qDeleteAll( pointList );
215 point->addMValue( m );
217 pointList.append( point.release() );
222 qDeleteAll( pointList );
230 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
233 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
236 pointList.append(
new QgsPoint( p->
x(), p->
y() ) );
238 sipReleaseType( p, sipType_QgsPointXY, state );
240 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
243 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
246 pointList.append( p->
clone() );
248 sipReleaseType( p, sipType_QgsPoint, state );
259 qDeleteAll( pointList );
262 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats." ).arg( i ) .toUtf8().constData() );
284 QgsMultiPoint(
const QVector<double> &x,
const QVector<double> &y,
285 const QVector<double> &z = QVector<double>(),
286 const QVector<double> &m = QVector<double>() )
SIP_HOLDGIL;
307 if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
309 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
314 return sipConvertFromType( sipCpp->pointN( a0 ), sipType_QgsPoint, NULL );
328 const QgsPoint *pointN(
int index )
const;
334 bool fromWkt(
const QString &wkt )
override;
335 void clear()
override;
345 bool isValid( QString &error
SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() )
const override SIP_HOLDGIL;
368 SIP_PYOBJECT __repr__();
370 QString wkt = sipCpp->asWkt();
371 if ( wkt.length() > 1000 )
372 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
373 QString
str = QStringLiteral(
"<QgsMultiPoint: %1>" ).arg( wkt );
374 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );