81 if ( !PySequence_Check( a0 ) )
83 PyErr_SetString( PyExc_TypeError, u
"A sequence of QgsPoint, QgsPointXY or array of floats is expected"_s.toUtf8().constData() );
89 const int size = PySequence_Size( a0 );
90 QVector< QgsPoint * > pointList;
91 pointList.reserve( size );
94 for (
int i = 0; i < size; ++i )
96 PyObject *value = PySequence_GetItem( a0, i );
99 qDeleteAll( pointList );
101 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
106 if ( PySequence_Check( value ) )
108 const int elementSize = PySequence_Size( value );
109 if ( elementSize < 2 || elementSize > 4 )
111 qDeleteAll( pointList );
114 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() );
122 PyObject *element = PySequence_GetItem( value, 0 );
125 qDeleteAll( pointList );
127 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
133 const double x = PyFloat_AsDouble( element );
134 Py_DECREF( element );
135 if ( PyErr_Occurred() )
137 qDeleteAll( pointList );
144 element = PySequence_GetItem( value, 1 );
147 qDeleteAll( pointList );
150 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
156 const double y = PyFloat_AsDouble( element );
157 Py_DECREF( element );
158 if ( PyErr_Occurred() )
160 qDeleteAll( pointList );
167 auto point = std::make_unique< QgsPoint >( x, y );
168 if ( elementSize > 2 )
170 element = PySequence_GetItem( value, 2 );
173 qDeleteAll( pointList );
176 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
182 const double z = PyFloat_AsDouble( element );
183 Py_DECREF( element );
184 if ( PyErr_Occurred() )
186 qDeleteAll( pointList );
192 point->addZValue( z );
194 if ( elementSize > 3 )
196 element = PySequence_GetItem( value, 3 );
199 qDeleteAll( pointList );
202 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1."_s.arg( i ) .toUtf8().constData() );
208 const double m = PyFloat_AsDouble( element );
209 Py_DECREF( element );
210 if ( PyErr_Occurred() )
212 qDeleteAll( pointList );
218 point->addMValue( m );
220 pointList.append( point.release() );
225 qDeleteAll( pointList );
233 if ( sipCanConvertToType( value, sipType_QgsPointXY, SIP_NOT_NONE ) )
236 QgsPointXY *p =
reinterpret_cast<QgsPointXY *
>( sipConvertToType( value, sipType_QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
239 pointList.append(
new QgsPoint( p->
x(), p->
y() ) );
241 sipReleaseType( p, sipType_QgsPointXY, state );
243 else if ( sipCanConvertToType( value, sipType_QgsPoint, SIP_NOT_NONE ) )
246 QgsPoint *p =
reinterpret_cast<QgsPoint *
>( sipConvertToType( value, sipType_QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
249 pointList.append( p->
clone() );
251 sipReleaseType( p, sipType_QgsPoint, state );
262 qDeleteAll( pointList );
265 PyErr_SetString( PyExc_TypeError, u
"Invalid type at index %1. Expected QgsPoint, QgsPointXY or array of floats."_s.arg( i ) .toUtf8().constData() );
287 QgsMultiPoint(
const QVector<double> &x,
const QVector<double> &y,
288 const QVector<double> &z = QVector<double>(),
289 const QVector<double> &m = QVector<double>() )
SIP_HOLDGIL;
310 if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
312 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
317 return sipConvertFromType( sipCpp->pointN( a0 ), sipType_QgsPoint, NULL );
337 bool fromWkt(
const QString &wkt )
override;
338 void clear()
override;
389 SIP_PYOBJECT __repr__();
391 QString wkt = sipCpp->asWkt();
392 if ( wkt.length() > 1000 )
393 wkt = wkt.left( 1000 ) + u
"..."_s;
394 QString str = u
"<QgsMultiPoint: %1>"_s.arg( wkt );
395 sipRes = PyUnicode_FromString( str.toUtf8().constData() );