1

I want to use ogr2ogr to import data into a PostgreSQL database. Therefore, I create the database like this:

sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt update
sudo apt install postgresql
sudo apt install postgis

sudo su postgres
psql
DROP DATABASE globcit;
CREATE DATABASE globcit;
\q
exit

Afterwards, I want to copy polygons from an OSM pbf file to this data base.

ogr2ogr -f PostgreSQL PG:dbname=globcit -nlt GEOMETRY 
-sql "select * from multipolygons where natural=\'water\'" 
-progress lakes turkey-latest.osm.pbf    

(formatted for better reading, usually one-liner)

However I get the error:

FAILURE:
Unable to open datasource `lakes' with the following drivers.
  -> PCIDSK
  -> netCDF
  -> JP2OpenJPEG
  -> PDF
  -> ESRI Shapefile
....

what am I missing?

1
  • Remove the word lakes. Or if you want that to be the table name, use -nln lakes.
    – user30184
    Nov 22, 2017 at 13:05

1 Answer 1

1

A few things.

You installed PostGIS. But you did not activate it for the database.

So in the PSQL (after CREATE DATABASE globcit;) you need to run:

CREATE EXTENSION postgis;

Then you have a space in the file name.

So the ogr2ogr command should be:

ogr2ogr -f PostgreSQL PG:dbname=globcit -nlt GEOMETRY -sql "select * from multipolygons where natural='water'" -progress -nln lakes turkey-latest.osm.pbf

But it might still fail. The -sql statement may have errors.

2
  • Thanks, that worked with a few changes, perhaps you could add them: ogr2ogr -f PostgreSQL PG:dbname=globcit -nlt GEOMETRY -sql "select * from multipolygons where natural='water'" -progress -nln lakes turkey-latest.osm.pbf
    – loki
    Nov 22, 2017 at 15:11
  • Edited. You should have mention the file name. Nov 22, 2017 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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