3

can you help me with importing planet.osm file to my PostGist db? I am new in this and I found tutorials only for linux.

There are some commands, but I do not know how use it ... I will be grateful for some step by step tutorial. I'm using GeoServer if it is important information for us to help me. Thanks for advices.

edit: I used osm2pgsql -s -U postgres -d nameofdatabase name.osm but unsuccessful because I have error with no database found.

Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
  • Did you already read https://wiki.openstreetmap.org/wiki/PostGIS/Installation and https://help.openstreetmap.org/questions/8363/how-to-setup-postgis-server-and-import-osm-file-on-windows ? Also be aware that this is not officially supported so you might run into various problems. – scai Oct 07 '16 at 08:41

1 Answers1

1

I used OGR2OGR to import osm data in pbf format on Windows (Windows 10, Posgres 9.6 with Postgis 2.3). You can use OGR2OGR from the "OSgeo42 shell", which comes with QGIS or you can get Osgeo4w separately here). The steps are something like this:

  • Create a new database: create database db_for_osm
  • Create Postgis extension in your db. In SQL create extension postgis
  • Now you can run OGR2OGR. Open the "OSGEO4W shell". This will open a command window with all the environment variables set. The command will be something like ogr2ogr -f PostgreSQL PG:"dbname='db_for_osm' host='localhost' port='5432' user='myuser' password='mypassword'" planet.osm.pbf

My large upload took a couple of days to complete, so be prepared for this to take a long time - I suggest you do a test with a small region first - for the test I did for this answer I downloaded a city from Mapzen.

mlinth
  • 2,968
  • 6
  • 30
  • 30
  • this not very helphull becouse I use geoserver not qgis, and I do not how to do this for geoserver :/ – Denis Stephanov Oct 07 '16 at 15:04
  • Step one is to get the data into Postgis, step two is to connect geoserver to the database... If you follow the link in my answer to OGR2OGR you can get to a download page where you can install osgeo4w - then you can import as above. Once you've imported you can do your geoserver stuff... – mlinth Oct 07 '16 at 17:03
  • my bigest problem is import data to postgis .. I'm trying OGR2OGR but not successful – Denis Stephanov Oct 07 '16 at 18:19
  • "not successful" does not really give enough to go on... I just managed to import a file, will update my answer with the steps I followed. If these steps don't work for you, I suggest you post another question specifically on ogr2ogr and describe the exact steps you followed and the exact error you get. – mlinth Oct 08 '16 at 19:05
  • sorry I did not see your question ... I try your command but it give me error : Unable to open datasource `host=localhost' with the following drivers. ... and when I switch single quotes to double quotes it give error about PostgreSQL driver – Denis Stephanov Feb 21 '17 at 17:14
  • this works really fine. thanks. – sutan Mar 11 '22 at 09:17