83 if ( !PySequence_Check( a0 ) )
85 PyErr_SetString( PyExc_TypeError, u
"A sequence of QgsPoint, QgsPointXY or array of floats is expected"_s.toUtf8().constData() );
91 const int size = PySequence_Size( a0 );
92 QVector< QgsPoint * > pointList;
93 pointList.reserve( size );
96 for (
int i = 0; i < size; ++i )
98 PyObject *value = PySequence_GetItem( a0, i );
101 qDeleteAll( pointList );
103 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
108 if ( PySequence_Check( value ) )
110 const int elementSize = PySequence_Size( value );
111 if ( elementSize < 2 || elementSize > 4 )
113 qDeleteAll( pointList );
116 PyErr_SetString( PyExc_TypeError, u
"Invalid sequence size at index %1. Expected an array of 2-4 float values, got %2."_s.arg( i ).arg( elementSize ).toUtf8().constData() );
124 PyObject *element = PySequence_GetItem( value, 0 );
127 qDeleteAll( pointList );
129 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
135 const double x = PyFloat_AsDouble( element );
136 Py_DECREF( element );
137 if ( PyErr_Occurred() )
139 qDeleteAll( pointList );
146 element = PySequence_GetItem( value, 1 );
149 qDeleteAll( pointList );
152 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
158 const double y = PyFloat_AsDouble( element );
159 Py_DECREF( element );
160 if ( PyErr_Occurred() )
162 qDeleteAll( pointList );
169 auto point = std::make_unique< QgsPoint >( x, y );
170 if ( elementSize > 2 )
172 element = PySequence_GetItem( value, 2 );
175 qDeleteAll( pointList );
178 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
184 const double z = PyFloat_AsDouble( element );
185 Py_DECREF( element );
186 if ( PyErr_Occurred() )
188 qDeleteAll( pointList );
194 point->addZValue( z );
196 if ( elementSize > 3 )
198 element = PySequence_GetItem( value, 3 );
201 qDeleteAll( pointList );
204 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
210 const double m = PyFloat_AsDouble( element );
211 Py_DECREF( element );
212 if ( PyErr_Occurred() )
214 qDeleteAll( pointList );
220 point->addMValue( m );
222 pointList.append( point.release() );
227 qDeleteAll( pointList );
235 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
238 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
241 pointList.append(
new QgsPoint( p->
x(), p->
y() ) );
243 sipReleaseType( p, sipType_QgsPointXY, state );
245 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
248 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
251 pointList.append( p->
clone() );
253 sipReleaseType( p, sipType_QgsPoint, state );
264 qDeleteAll( pointList );
267 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats."_s.arg( i ) .toUtf8().constData() );
290 QgsMultiPoint(
const QVector<double> &x,
const QVector<double> &y,
291 const QVector<double> &z = QVector<double>(),
292 const QVector<double> &m = QVector<double>() )
SIP_HOLDGIL;
314 if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
316 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
321 return sipConvertFromType( sipCpp->pointN( a0 ), sipType_QgsPoint, NULL );
342 bool fromWkt(
const QString &wkt )
override;
343 void clear()
override;
395 SIP_PYOBJECT __repr__();
397 QString wkt = sipCpp->asWkt();
398 if ( wkt.length() > 1000 )
399 wkt = wkt.left( 1000 ) + u
"..."_s;
400 QString str = u
"<QgsMultiPoint: %1>"_s.arg( wkt );
401 sipRes = PyUnicode_FromString( str.toUtf8().constData() );