Skip to content

Import a Shapefile into PostGIS

Billy Charlton edited this page Jun 30, 2017 · 2 revisions

« Back to Recipes for typical tasks


(This page could use some help!)

PostGIS comes with a tool called shp2pgsql which reads an ESRI shapefile and creates a .sql file which can be loaded into PostGIS.

But, you have to have PostGIS installed on your machine to use the command-line tool. Since PostGIS isn't installed automatically with pgAdmin, and since the Windows port of PostGIS is a little janky, my recommendation is that you copy the needed shapefiles to a folder on the database server, and SSH into the server to run the shp2pgsql tool.

scp my_shapefile.* sfcta@prospector-db:
ssh sfcta@prospector-db
shp2pgsql -s 4326 -d geo my_shapefile schema.tablename > my_shapefile.sql
psql -U sfcta < my_shapefile.sql
Clone this wiki locally