Tuesday, 17 December 2019

postgis - Force dimensionality with shp2pgsql


After invoking:


shp2pgsql -W "latin1" theshape.shp > thesql.sql


My console responds with:


Shapefile type: PolygonZ
Postgis type: MULTIPOLYGON[2]


Note the shapefile type is PolygonZ. The result is, I have to manually edit the thesql.sql file and wrap the geometry column in ST_Force_2D() before executing the SQL, otherwise, Postgres complains I'm trying to import a 3D shape into a 2D column.


How can I force dimensionality to 2 with shp2pgsql? Alternatively, can I force it in QGIS?



Answer



shp2pgsql -t 2D theshape.shp > thesql.sql

For a full list of options you can run


shp2pgsql --help

Edit:


You'll probably also want to define the projection and throw in a spatial index. You can do so with



shp2pgsql -t 2D -s 4326 -I theshape.shp > thesql.sql

Just replace 4326 with the EPSG code of your coordinate reference system.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...