Working on Windows with ogr2ogr

Managing data manipulation with ogr2ogr can be a satisfying and rewarding experience. It can bring joy and a more peaceful nature into your life. It works.

Examples

Inventory:

  1. shapefile named esri.shp
  2. PostgreSQL database named dataplace and its handy companion pgAdmin III
  3. Copy of ogr2ogr.exe

Example 1 - the straight import

 ogr2ogr -f "PostgreSQL" PG:"dbname=dataplace user=username password=password  host=localhost port=5432" c:\some-directory\esri.shp

Example 2 - give me only the data north of 35 lat

 ogr2ogr -f "PostgreSQL" PG:"dbname=dataplace user=username password=password host=localhost port=5432" -where "lat_column>35" c:\some-directory\esri.shp

Example 3 - Changing projection data

 ogr2ogr testout.shp testin.shp -a_srs EPSG:4326

Display

Now go to pgAdmin III and find the database name dataplace. Under the schemas you should see a list of tables, and within them your safely stored data :)

See also http://giswiki.hsr.ch/HowTo_OGR2OGR (NOTE: german)