PostgreSQL and PostGIS

Convert Shapefiles to PostGIS Tables

Document Information
Document ID: 
app2009-008

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.

PostgreSQL and PostGIS

PostgreSQL

PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows.

 

PostGIS

PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS "spatially enables" the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI's SDE or Oracle's Spatial extension. PostGIS follows the OpenGIS "Simple Features Specification for SQL" and has been certified as compliant with the "Types and Functions" profile.

Syndicate content