Bug report #18798

Polygon Shapefile loaded as Multipolygon

Added by Peter Gipper almost 6 years ago. Updated over 5 years ago.

Status:Rejected
Priority:High
Assignee:-
Category:Geometry
Affected QGIS version:3.0.0 Regression?:No
Operating System:Windows 7 Easy fix?:No
Pull Request or Patch supplied:No Resolution:wontfix
Crashes QGIS or corrupts data:No Copied to github as #:26684

Description

If a polygon shapefile is loaded in QGIS 3, the geometries are of type MULTIPOLYGON whereas in older Versions of QGIS (2.14, 2.18) they are correctly loaded as type POLYGON.

(Strangely, a shapefile that is created as type POLYGON with including Z Values option checked is not loaded as MULTI*.)

griglia.zip - SHP with single geometries to reproduce issue 18798 (894 Bytes) Gabriele Monfardini, 2018-10-11 12:11 PM

History

#1 Updated by Gabriele Monfardini over 5 years ago

Loading a shapefile to postgis using DB Manager a polygon shapefile is imported as multipolygon even if the option "Create single part geometries instead of multi part" is checked.

Having a quick look at the code in qgspostgresprovider.cpp in createEmptyLayer I cannot find where this option is checked.

QGIS: 3.2.3
PostGIS: 2.5
PostgreSQL: 10.5

#2 Updated by Giovanni Manghi over 5 years ago

Gabriele Monfardini wrote:

Loading a shapefile to postgis using DB Manager a polygon shapefile is imported as multipolygon even if the option "Create single part geometries instead of multi part" is checked.

Having a quick look at the code in qgspostgresprovider.cpp in createEmptyLayer I cannot find where this option is checked.

QGIS: 3.2.3
PostGIS: 2.5
PostgreSQL: 10.5

that option name in DB Manager always has been misleading and SHOULD really be changed. DB Manager by default always imports vectors in "MULTI" tables regardless of the input. With that option active you can have a NOT MULTI input imported into a NOT MULTI table, if you use that option and your input is MULTI you'll get an error.

#3 Updated by Nyall Dawson over 5 years ago

  • Resolution set to wontfix
  • Status changed from Open to Rejected

This change is by design - shapefiles don't have a definition of single/multi geometries (unless they are point layers), so we upgrade all shapefiles polygons/lines to multi type for consistency (as qgis has strict geometry typing).

#4 Updated by Gabriele Monfardini over 5 years ago

Giovanni Manghi wrote:

that option name in DB Manager always has been misleading and SHOULD really be changed. DB Manager by default always imports vectors in "MULTI" tables regardless of the input. With that option active you can have a NOT MULTI input imported into a NOT MULTI table, if you use that option and your input is MULTI you'll get an error.

Probably I need to add a little more background details.

The fact is that if you are importing a NOT MULTI shapefile in a new table, and you check the option in DB Manager you expect that resulting table will be NOT MULTI.
I know that shapefiles are always multi and it's ok for me to fail if there are multi parts, but in my case there are not.
One would expect a behaviour similar to shp2pgsql -S switch, i.e. will create a single geometry field and will fail if there are multi geometry features.

Moreover, this is a regression from 2.18.14.
In 2.18.14 a Polygon shapefile with no multi geometry will be imported in a new table which geometry field is of type geometry(Polygon,srid) or geometry(MultiPolygon,srid) depending on whether the "Create single part geometries instead of multi part" checkbox is checked or not.

Uploading a simple shapefile to reproduce the problem.

QGIS 2.18.14 (Windows 10 64bit)
PostgreSQL/PostGIS: 10/2.4
srid chosen: 3003
Results: if che checkbox is checked, geometry field of the table is geometry(Polygon,3003) else is geometry(MultiPolygon,3003)

QGIS 3.2.3 (Windows 10 64bit, Ubuntu 18.04 64bit)
PostgreSQL/PostGIS: 10/2.4 - the same as before
srid chosen: 3003
Results: geometry field of the table is geometry(MultiPolygon,3003) if the checkbox is checked or not

#5 Updated by Giovanni Manghi over 5 years ago

The fact is that if you are importing a NOT MULTI shapefile in a new table, and you check the option in DB Manager you expect that resulting table will be NOT MULTI.

that is what the option does. What the option does NOT is converting MULTI geometries to fit NOT MULTI table after the import. But the name of the option makes people believe is the latter, not the former.

#6 Updated by Gabriele Monfardini over 5 years ago

that is what the option does. What the option does NOT is converting MULTI geometries to fit NOT MULTI table after the import. But the name of the option makes people believe is the latter, not the former.

Fully agree on this.

Even if it is probably not an high priority issue, I think current behaviour is a regression w.r.t. 2.18.
Is it possible to leave this issue open?

#7 Updated by Giovanni Manghi over 5 years ago

Even if it is probably not an high priority issue, I think current behaviour is a regression w.r.t. 2.18.
Is it possible to leave this issue open?

is not a regression, in QGIS 3 changed the way the shapefiles are interpreted... now they are always loaded as MULTI, so they will be always imported as MULTI, at least using QGIS DB manager (and possibly other QGIS tools).

#8 Updated by Gabriele Monfardini over 5 years ago

is not a regression, in QGIS 3 changed the way the shapefiles are interpreted... now they are always loaded as MULTI, so they will be always imported as MULTI, at least using QGIS DB manager (and possibly other QGIS tools).

IMHO, from user perspective, it is something that worked before, but it is not working as usual anymore.

And, in fact, I'm commenting this issue on behalf of some of my colleagues, who are used to import single part shapefiles but in 3.2.3 doing the same actions in the same UI, the behaviour is different.

Since current behaviour is deemed to be correct, probably it would be better to specify that the option is ignored in case of import in a new table

Also available in: Atom PDF