osm2pgsql on Windows

How to run osm2pgsql on Windows in 5 steps:

  1. Download and Install PostgreSQL for Windows (EnterpriseDB includes also pgAdmin)
  2. Download PostGIS with SFCGA support (from Experimental Builds) and install downloaded experimental binaries simply by copying the contents of the respective folders in the zip file to your PostgreSQL install and when prompted to overwrite, overwrite
  3. Install Cygwin
  4. Download osm2pgsql Cygwin package (Unzip it into Cygwin's "packages\osm2pgsql" directory)
  5. That's all, let's run osm2pgsql and import some data
    • Export map area (OSM file) from Open Street Map and save it to packages\osm2pgsql\your-map-area.osm
    • Create new database and enable following extensions
      CREATE EXTENSION IF NOT EXISTS plpgsql;
      CREATE EXTENSION IF NOT EXISTS postgis;
      CREATE EXTENSION IF NOT EXISTS postgis_sfcgal;
      
    • Modify packages\osm2pgsql\default.style if necessary (e.g. to add more fields to import into database)
    • Run Cygwin and execute following commands:
      • Navigate to osm2pgsql directory
      • Import new (create) OSM data (area-1.osm) into database (-c means create)
      • Import additional (append) OSM data (area-2.osm) into database (-a means append)


Back