Opened 11 years ago

Closed 8 years ago

#4939 closed defect (invalid)

shapefile to postgresql : ERROR: Geometry type (MultiPolygon) does not match column type (Polygon)

Reported by: strk Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.9.2
Severity: normal Keywords:
Cc:

Description

This shapefile: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_map_subunits.zip

With this commandline:

ogr2ogr -f PostgreSQL PG: ne_10m_admin_0_map_subunits.shp

Results in this error:

Warning 1: Geometry to be inserted is of type 3D Multi Polygon, whereas the layer geometry type is 3D Polygon.
Insertion is likely to fail
ERROR 1: INSERT command for new feature failed.
ERROR:  Geometry type (MultiPolygon) does not match column type (Polygon)

Expected behavior: ogr2ogr uses a MultiPolygon and casts all geoms to a multi

Change History (7)

comment:1 by Even Rouault, 11 years ago

Resolution: invalid
Status: newclosed

Add -nlt MULTIPOLGON (or better with 1.10dev, -nlt PROMOTE_TO_MULTI so that it works with any geometry base type)

comment:2 by strk, 11 years ago

thank you, but why is the default "polygon" when the input also contains "multipolygon" ?

comment:3 by Even Rouault, 11 years ago

The issue is with the shapefile format itself which, at the level of its header, has a single value, POLYGON, to indicate the 2 concepts of POLYGON or MULTIPOLYGON. So the OGR Shapefile driver returns "polygon", because - most of the time (but of course not always...) - there are just one part polygons.

We could advertize a layer of type MultiPolygon, and automatically turn polygons into multipolygons, but, I think - this is perhaps an old-dated reason - this could cause issues with some output formats, or client applications, that wouldn't deal well with multipolgons. Another alternative would be to scan the whole shapefile at open time to determine if there are some multipart polygons and advertize a consistant geometry type (polygon if there are only single part polygons, or multipolygon if there are at least one multipolygon and automatic promotion of polygons to multipolygons). I think that's what Spatialite does with its VirtualShape driver, but this is probably not acceptable in the OGR context where the time for the initial scanning could be prohibitive for some use cases.

comment:4 by Even Rouault, 11 years ago

This might be something to revise for GDAL 2.0, so I've added that topic in http://trac.osgeo.org/gdal/wiki/GDAL20Changes?action=diff&version=27

comment:5 by Even Rouault, 11 years ago

Resolution: invalid
Status: closedreopened

comment:6 by strk, 11 years ago

FYI: we took the first path with the postgis loader (advertise a layer as Multi*) and then added a switch to force single.

comment:7 by Jukka Rahkonen, 8 years ago

Resolution: invalid
Status: reopenedclosed

Did not go to GDAL 2.0, reopen when 3.0 is close.

Note: See TracTickets for help on using tickets.