Is it possible, with QGIS, to get the area of a single part of a multi polygon? Or do I have to split them into single polygons?
2 Answers
Using Field Calc and Expressions:
expression used:
array_foreach(
generate_series(1, num_geometries($geometry)),
round(area(geometry_n( $geometry,@element)),0))
Using a script, you can get easily the areas.
- You need to check if it is multipart.
parts
method ofQgsGeometry
returns an iterator for parts
layer = iface.activeLayer()
for feat in layer.getFeatures():
geom = feat.geometry()
if geom.isMultipart():
areas = sorted([part.area() for part in geom.parts()])
print(feat.id(), areas)