I want to import OSM data into a PostGIS database running under windows. After a web search I learned that I should use osmosis. But most of the explanations are for Linux. But I have to use windows. Is there a detailed description how to do that with Windows?
-
1"Osmosis quick install" in the OSM wiki at wiki.openstreetmap.org/wiki/Osmosis/Quick_Install_%28Windows%29 should be a starting point.– til_bAug 31, 2015 at 6:51
-
Also check geofabrik.de for some premade shapefiles based on OSM datasets that are ready for consumption.– nickvesMay 4, 2016 at 23:27
2 Answers
Osmosis is the swiss-knife for OSM data and therefore a great piece of software to handle OSM data. I'd recommend to follow the steps below to succesfully import OSM data into a PostGIS database in a windows environment:
- First of all you need to download and install PostgreSQL with a PostGIS extension and download the latest stable version of osmosis.
- Then you need to create the hstore extension using pgAdmin to store osm-tags in PostGIS:
CREATE EXTENSION hstore;
- Create a database-schema for OSM data: Copy the code from
YourPathToOsmosis\script\pgsnapshot_schema_0.6.sql
into pgAdmin and execute it. Do the same withYourPathToOsmosis\script\pgsnapshot_schema_0.6_linestring.sql
to enable linestrings (there are other database schemas which might suite your needs. I prefer pgsnapshot because every single tag is imported. If you primarily want to render OSM data you'd better use the osm2pgsql schema). - For better performance add indices: Again, execute
CREATE INDEX idx_nodes_tags ON nodes USING GIN(tags);
andCREATE INDEX idx_ways_tags ON ways USING GIN(tags);
andCREATE INDEX idx_relations_tags ON relations USING GIN(tags);
within pgAdmin. - Now your database is ready to be filled with OSM data. Download your required OSM extract (e.g. from the Geofabrik download server) and use osmosis within the commande line to import a *.pbf-file:
"YourPathToOsmosis\bin\osmosis" --read-pbf file="C:\YourPathToOSMFile\osm_file.osm.pbf" --write-pgsql host="localhost" database="yourDBname" user="postgres" password="yourPW"
Apart from osmosis, you can use osm2pgsql to populate a Postgis database.
For links to Windows builds, see https://github.com/openstreetmap/osm2pgsql/issues/17 and https://github.com/openstreetmap/osm2pgsql/issues/472
The advantage of osm2pgsql is that you will get GIS-ready tables with the same content as used by the rendering toolchain.