Convert Shapefiles to PostGIS Tables

There is a relatively simple command that comes with PostGIS that allows you to convert ESRI shapefiles into geometry-enabled PostgreSQL tables. The following is a pair of commands that first converts the shapefile by creating an SQL statement to insert the records, and then pipes that output into a command which loads it into the appropriate database.

shp2pgsql -s <srid> <path to .shp file> <schema name>.<PostgreSQL table name> | psql -d <database name> -U <username>

An example command may look like this:

shp2pqsql -s 4326 /mnt/data-store/geoserver/gsvr/data/data/shapefiles/MajorElements_EarthChem.shp azgs.majorelements_earthchem 
| psql -d arizonageology -U gisuser

Run this command at a prompt on the machine that runs the PostgreSQL database. It will prompt you for the password of the user you've specified.



shp2pgsql shaperoads roadstable roadsdb |  psql -d roadsdb



你可能感兴趣的:(Convert Shapefiles to PostGIS Tables)