4

I have a layer in QGIS that is a Multisurface layer currently stored on a PostGIS server I want to add this layer as a MultiPolygon layer to PostGIS using QGIS.

Can I specify this somehow when I save/export to QGIS? The only workaround I found is exporting the layer to a shape file loading it and exporting it then to PostGIS.

2
+250
  • within PostGIS:
    CREATE TABLE <multipolygon_layer> AS
      SELECT <id>,
             ...,
             ST_CurveToLine(<geom>) AS <geom>
      FROM   <multisurface_layer>
    ;
    
  • using ogr2ogr (GDAL > 3.0.5):
    ogr2ogr -f PostgreSQL <pg_conn> -nln <multipolygon_layer_name> -nlt CONVERT_TO_LINEAR -nlt PROMOTE_TO_MULTI <source>
    
    or, if the approximated linear geometries will always be areal, simply
    ogr2ogr -f PostgreSQL <pg_conn> -nln <multipolygon_layer_name> -nlt MULTIPOLYGON <source>
    
3
  • thanks for the postgis solution. However for ogr it should be from multisurface to multipolygon In fact I've found the solution for the ogr2ogr by myself (simply -nlt MULTIPOLYGON ). Please update your answer. – radouxju Apr 12 at 12:56
  • @radouxju I added the extra -nlt flag, which has the same effect, and a note about using the MULTIPOLYGON option. I consider using the appropriate flags as the 'more correct' answer, as these will handle all SQL-MM curve types, while using the MULTIPOLYGON option fails for when a non-linear type can only be approximated as a LineString. If that could ever be the case, or if you really want to have a mixed type relation, is another question. – geozelot Apr 12 at 14:46
  • thanks for completing the answer. – radouxju Apr 13 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.