6

I need use ogr2ogr tool for import osm into PostgreSQL database. I've tried this command:

ogr2ogr -f PostgreSQL PG:"dbname='OSM_DB' host='localhost' port='5432' user='postgres' password='postgres'" "E:\Sources\OSM Data\map.osm.pbf"

I'll use ogr2ogr.exe which is default added into my PostgreSQL 9.6 installation bin folder. It return this error:

ERROR 1: Unable to find driver PostgreSQL'. The following drivers are available: ->PCIDSK' -> JP2OpenJPEG' ->PDF' -> ESRI Shapefile' ->MapInfo File' -> UK .NTF' ->OGR_SDTS' -> S57' ->DGN' -> OGR_VRT' ->REC' -> Memory' ->BNA' -> CSV' ->GML' -> GPX' ->KML' -> GeoJSON' ->OGR_GMT' -> GPKG' ->SQLite' -> ODBC' ->WAsP' -> PGeo' ->MSSQLSpatial' -> OpenFileGDB' ->XPlane' -> DXF' ->Geoconcept' -> GeoRSS' ->GPSTrackMaker' -> VFK' ->PGDUMP' -> OSM' ->GPSBabel' -> SUA' ->OpenAir' -> OGR_PDS' ->WFS' -> HTF' ->AeronavFAA' -> Geomedia' ->EDIGEO' -> GFT' ->SVG' -> CouchDB' ->Cloudant' -> Idrisi' ->ARCGEN' -> SEGUKOOA' ->SEGY' -> XLS' ->ODS' -> XLSX' ->ElasticSearch' -> Walk' ->CartoDB' -> AmigoCloud' ->SXF' -> Selafin' ->JML' -> PLSCENES' ->CSW' -> VDV' ->TIGER' -> AVCBin' ->AVCE00' -> `HTTP'

Can you tell me how can I fix it ? I am using windows OS.

  • 1
    Install GDAL with OSGeo4W or from gisinternals.com and you should get PostGIS driver. The list you show is very very odd. There must be some problem in that installed version. – user30184 Feb 21 '17 at 20:23
  • I'll install it and run same command from OSGeo4W bin directory and give this error: FAILURE: Unable to open datasource `data.osm.pbf' with the following drivers. – Denis Stephanov Feb 21 '17 at 20:48
  • 1
    Use simple paths and filenames without spaces at least when your test. Include full enough commands and error reports so others can repeat the test. Check that you really have also OSM driver with ogrinfo --formats. Be systematic. Add --debug on into ogr2ogr command for getting more info. – user30184 Feb 21 '17 at 20:55
5

Solution is install OSGeo4W GDAL, and run ogr2ogr from bin folder. (OsGeo4W shell not working for me. Give it me error unable load datasource *.osm.pbf).

After installation run command from directory where *.osm.pbf is located

ogr2ogr -f PostgreSQL PG:"dbname='myDB' host='localhost' port='5432' user='postgres' password='postgres'" "data.osm.pbf"

otherwise, give full file path. and done :) additional information about other parameters are here: http://www.gdal.org/drv_osm.html

1

*.osm.pbf is not a postgresql file... To import osm into postgresql use osm2pgsql, imposm or any other tool made for this...

If you really need to use ogr2ogr check your version

ogr2ogr.exe --version 
GDAL 2.1.2, released 2016/10/24

This one is working - have checked now.

  • I wanted to try ogr2ogr because I found commands for it to import osm and ogr2ogr is default in my bin folder of PostgreSQL, so I hoped imported schema after calling pgr_CreateTopology will be working for routing better as schema from osm2pgsql. I am still unlucky with removing line from osm2po result – Denis Stephanov Feb 21 '17 at 19:56
  • GDAL belongs to tools which are made for converting OSM .pbf files into other vector formats gdal.org/drv_osm.html. – user30184 Feb 21 '17 at 20:29
  • @user30184 Yes, you're right - among 100 other functions it also can read *.osm and *.pbf files. I meant tools created especially for converting osm into PG. I haven't heard about any osm with ogr2ogr in production. After all read please last questions of Denis - he's looking for resolution where there is no problem... Denis - no matter how you'll create your topology pg_routing will still search from full edge to full edge... cutting is necessary – Jendrusk Feb 21 '17 at 21:03
0

I got the same driver list as above.

I was able to solve this problem with guidance from the 'WHERE' command on windows OS.

Using 'WHERE ogr2ogr' I discover that that ogr2ogr could be found via three enviromental variable paths on my machine 1. PostgreSQL\bin 2. GDAL\bin and 3. OSgeo4W\bin.

I turns out that the computer will that the first environmental variable set in this case PostgreSQL.

If you delete the ogr2ogr.exe executable from your PostgreSQL\bin folder then the second available ogr2ogr from GDAL GIS internals will be found which contains the PostgreSQL driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.