Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Last active October 23, 2018 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/6590270 to your computer and use it in GitHub Desktop.
Save mhkeller/6590270 to your computer and use it in GitHub Desktop.
Shapefile to PostGIS table.
# SRID is the projection's EPSG code. To find yours, open up the prj file in a text editor and search for that name at http://spatialreference.org/
# The schema is probably already named `public` and the database name is perhaps your username.
# To list your schemas use `\dn` after running `psql`.
# To get info about your current database connnection use `\conninfo`.
# In SQL, get the database name with `select current_database() ;`
# The -D flag will use the postgres dump format, which will be much faster than single row inserts. if any single row fails,
# which is also good to know — instead of not knowing if you insert row by row
# shp2pgsql -I -D -s <SRID> <PATH/TO/SHAPEFILE> <SCHEMA>.<DBTABLE> | psql -d <DATABASE>
shp2pgsql -I -D -s 4629 Tract_2010Census_DP1.shp public.census_tracts | psql -d mike
# 4629 is the EPSG code for NAD83, use 4326 if you're importing lat/lng data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment