PostGIS Geometry type not matching column type in QGIS
I use ogr2ogr to automate ingest of shapefiles into a PostGIS database. Specifically with regard to the question, use the option:
-nlt PROMOTE_TO_MULTI
This will force ogr2ogr to promote POLYGON geometries to MULTIPOLYGON, avoiding the error. A very simple example:
ogr2ogr -f "PostgreSQL" PG:"dbname='<my_db>'" -nlt PROMOTE_TO_MULTI <shapefile>
I have omitted pgsql host/auth details. To batch multiple shapefiles you might do something like:
find ./ -name *.shp | xargs -n1 ogr2ogr <ogr2ogr args omitting the shapefile>
This appears to be a known issue that won't be fixed: see http://hub.qgis.org/issues/5328
If you need a workaround, try changing your table's geometry column type to a generic 'geometry':
ALTER TABLE my_table ALTER COLUMN geom SET DATA TYPE geometry;
After you've done your import, you can revert back to MultiPolygon
:
ALTER TABLE my_table ALTER COLUMN geom
SET DATA TYPE geometry(MultiPolygon) USING ST_Multi(geom);
Alternatively, try loading your data using ogr2ogr.
Spit is unmaintained and not recommended anymore. I'd suggest using the processing toolbox and choosing the "Import into PostGIS" algorithm. I've had much more luck using that routine. A few things to note:
- The database (connection name) parameter must match what you've named your database connection from the "Add PostGIS layer" dialog.
- The schema must already exist - it won't be created automatically