postgresqlshapefileogr2ogr

Convert Tables in Postgresql to Shapefile


So far I have loaded all the parcel tables (with geometry information) in Alaska to PostgreSQL. The tables are originally stored in dump format. Now, I want to convert each table in Postgres to shapefile through cmd interface using ogr2ogr.

My code is something like below:

ogr2ogr -f "ESRI Shapefile" "G:\...\Projects\Dataset\Parcel\test.shp" PG:"dbname=parceldb host=localhost port=5432 user=postgres password=postgres" -sql "SELECT * FROM ak_fairbanks"

However, the system kept returning me this info: Unable to open datasource

PG:dbname='parceldb' host='localhost' port='5432' user='postgres' password='postgres'

With the following drivers.


Solution

  • There is pgsql2shp option also available. For this you need to have this utility in your system.

    The command that can be follow for this conversion is

    pgsql2shp  -u <username> -h <hostname> -P <password> -p 5434 -f <file path to save shape file> <database> [<schema>.]<table_name>
    

    This command has other options also which can be seen on this link.