// create a polygon QPolygonF polygon; polygon << QPointF(1,1) << QPointF(1,2) << QPointF(2,2) << QPointF(2,1); QgsGeometry geometry = QgsGeometry::fromPolygon(polygon); // check if the geometry is multipart if(geometry.isMultipart()) { qDebug() << "Geometry is multipart"; } else { qDebug() << "Geometry is not multipart"; }
// create a line string with multiple parts QgsPointXY point1(1, 1); QgsPointXY point2(2, 2); QgsPointXY point3(3, 1); QgsPointXY point4(4, 2); QgsPolyline polyline; polyline << point1 << point2 << point3; QgsPolyline polyline2; polyline2 << point3 << point4; QListIn this example, we create a multi-part line geometry and check if it is multipart using the isMultipart function. Since the geometry is composed of multiple parts, the output will show "Geometry is multipart". The function belongs to the QGIS C++ library.multilinestring; multilinestring << polyline << polyline2; QgsGeometry geometry = QgsGeometry::fromMultiPolyline(multilinestring); // check if the geometry is multipart if(geometry.isMultipart()) { qDebug() << "Geometry is multipart"; } else { qDebug() << "Geometry is not multipart"; }