[GIS] Multipolygon created from Scratch Layer

polygonqgis

Through this question and answer I've learned about the nature of Multipolygon shapefile, which was defined as multiple exterior rings.
In short, (1) it contains multiple exterior rings (polygons), and (2) its attribute table shows one record for these multiple features.

So my expectation was, by choosing Multipolygon in Create New Temporary Scratch Layer dialog I could produce such file, i.e. multi-geometry plus single record.
enter image description here

Choosing "Multipolygon" and create polygons with "Add feature",

enter image description here

then saving the scratch layer as shapefile, however, produced a polygon shapefile with multiple records. The picture below shows a purple shapefile named "test", which was created by "Save As" from the Scratch Layer. (RHS: Attribute table).
enter image description here
What did I do wrong? As multipolygon I anticipated a single record attribute table, but I see 4 records. Or, is this a bug?

(Note) Before saving, the Scratch layer (cyan "New scratch layer") also had 4 features in its attribute table, without attribute column.
enter image description here

Best Answer

From a formal point of view, I think that the object you have created is a multipolygon because it's a set of distinct polygons which don't satisfy one of the rules that define valid polygons (I report it from a previous answer):

The interior of every Polygon is a connected point set

So, referring to your sample object as a whole, this is sufficient to state that we are not talking about polygons here (instead, a multipolygon may be not a connected space).

Choosing the Polygon or Multipolygon option in the Create New Temporary Scratch Layer dialog only depends on what you are going to do with the layer and QGIS obviously doesn't know that (so, I don't think this could be an issue).

I remark that the difference between the two geometry types is purely formal (since shapefiles don't make a distinction between these objects) and I'll try to explain it better with an example which is partially inspired to @tallistroan's answer.

Regardless of what you choose in the Create New Temporary Scratch Layer dialog, you may edit your layer until to get this shape: enter image description here

which should be a multipolygon for the reasons explained above. Despite your initial choice doesn't affect what you can subsequently do with your layer, you made a formal mistake if you selected the "Polygon" option in the dialog; if this is the case, you will manage a multipolygon which is formally a polygon because this simple test from the Python Console:

layer = iface.activeLayer()
if layer.isValid():
    print layer.wkbType()

gives 3 as output (3 is the identifier for WKBPolygon types, while 6 is for WKBMultiPolygon, as defined in the QGIS API Documentation).

Made this clear, you were probably looking for a multipart object, which is a valid option for both polygons and multipolygons and takes in account a common attribute value which is shared by one or more features for creating a unique feature.

In the following figure I will try to explain what I intend for multipart object in both cases (in the multipart geometries, same colors belong to the same feature):

enter image description here

Related Question