ogr2ogr

ogr2ogr is a fantastic command line tool for accessing and manipulating geospatial data. Documentation is maintained at ogr2ogr docs. We recommend Geospatial Power Tools" by Tyler Mitchell as a reference.

Below we show several simple example queries using ogr2ogr. Text is below each screenshot.

Example 1

This simple example shows how the credentials are entered. We've extracted the critical habitat polygons from the Fish and Wildlife Service for the region Northeast of New York City using the "-spat" argument. In this example a geojson file is created.


ogr2ogr -f "GeoJSON" NE_crithab_poly.geojson PG:"host=db.v1.giraffegeo.com port=5432 dbname='giraffegeo11' user='demouser' password='**********'" "usfishandwildlifeservice.crithab_poly" -spat -74.25 40.47 -66.66 47.86             
                                        

Example 2

This example uses a simple "where" clause to select all the Delmarva Power transmission lines and export them to an ESRI shapefile.


ogr2ogr -f "ESRI Shapefile" delmarva.shp -where "owner='DELMARVA POWER'" PG:"host=db.v1.giraffegeo.com port=5432 dbname='giraffegeo11' user='*********' password='**********'" "usenergyinformationagency.electric_power_transmission_lines"                                         
                                        

Example 3

The "ogrinfo" command can be used to get the names of all the available tables and their geometry types.


ogrinfo PG:"host=db.v1.giraffegeo.com dbname='giraffegeo11' user='demouser' password='***********'"