Geography Reference
In-Depth Information
Basically, we just need to provide the name for the shapefile we want to
create and the connection information for the database. You probably
realize this means you can use this command from a remote machine.
Let's be wishy-washy and export our layer back out of the database:
$ pgsql2shp -f cities_out.shp gis_data cities_pg
Initializing... Done (postgis major version: 1).
Output shape: Point
Dumping: XXXXXXXX [606 rows].
Things worked as expected—we got all 606 cities out of the database
and into a new shapefile. We could use ogrinfo to check it out, but trust
me, it's the same as what went into the database. Notice that we didn't
specify anything for the database connection. That's because we ran
pgsql2shp on the same host as the database server. If we were doing an
export from a remote server, we would have to specify host , user , and
password . If your database server runs on a nonstandard port, you will
have to specify it as well.
If your table has more than one geometry column, you can specify
which to use for exporting the features with the -g switch. You might be
wondering how you get a table with more than one geometry column.
All I'll tell you is it didn't happen with shp2pgsql . Seriously, though,
creating a table with more than one geometry column is done program-
matically through SQL or custom applications using the programmer's
API for PostgreSQL.
That's pretty much the quick tour for getting data out of your Post-
greSQL database. There are other ways too, including writing custom
scripts using APIs that know how to talk to the database. Although
pgsql2shp works well for exporting to shapefiles, you might find that
ogr2ogr provides a better solution for exporting to other formats.
 
 
Search WWH ::




Custom Search