Given a file my_file.shp such those from Gadm e.g. US administrative divisions, where the coordinate reference system is latitude/longitude with WGS84 datum.

Input could actually be:

  1. Shapefile,
  2. ESRI personal geodatabase,
  3. ESRI file geodatabase,
  4. Google Earth .kmz,
  5. R (SpatialPolygonsDataFrame)

How to convert this input into a WGS84 PostGIS dump ?

  • This ogr2ogr may help: ogr2ogr -overwrite -f "PostgreSQL" PG:"host=myhost user=myuser dbname=mydb password=mypass" my_file.shp [ See: gis.stackexchange.com/questions/68417 ] – Hugolpz Aug 12 '13 at 6:39
  • 1
    shp2pgsql -I -s <SRID> <PATH/TO/SHAPEFILE> <SCHEMA>.<DBTABLE> – Ian Turton Aug 12 '13 at 8:01
  • Iant, your answer is helpful. Please open an answer and explain a bit (SRID, Schema, DBtable). – Hugolpz Aug 12 '13 at 8:04

PostGIS comes with a shapefile loader called shp2pgsql which converts a shapefile into the SQL statements that are needed to load the data into PostGIS. You can find a detailed description of the command and the options needed on this page.

But it boils down to something like:

shp2pgsql -I -s 4326 input.shp schema.table > output.sql
  • If i understand it well : shp2pgsql -I -s <SRID> <PATH/TO/SHAPEFILE> <SCHEMA>.<DBTABLE> > <TARGET_NAME>.sql or for a practical example shp2pgsql -I -s 4326 input.shp layer_rivers > output.sql . Could you confirm ? – Hugolpz Aug 12 '13 at 8:54

The simplest solution I can think of would be to import the shapefile into PostGIS using Shapefile to DBF loader (or if in another format write a scipt to upload using ogr2ogr). Then once in PostGIS you can create the dump file. If you use PgAdmin then both these operations are very easy as the shapefile loader is a plugin to PgAdmin and to dump, just right-click on your table and choose 'backup'.

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.