1

I download country cuts of OSM from GeoFabrik. When I import a country's PBF file into my PostGIS instance using ogr2ogr, it simply gives me a generically named set of tables (lines, points, multipolygons, etc).

Even if I rename the table, it does not change everything all the way down the database structure; so when I go to import a new country pbf file, it will give me:

ERROR 1: ERROR: relation "points_wkb_geometry_geom_idx" already exists

The ogr2ogr command I'm using is:

ogr2ogr -f PostgreSQL PG:"dbname='dbname' host='host' port='5432' user='username' password='password'" country-latest.osm.pbf -lco COLUMN_TYPES=other_tags=hstore --config OSM_MAX_TMPFILE_SIZE 1024

I have also tried the following using the -nln argument:

ogr2ogr -f PostgreSQL PG:"dbname='dbname' host='host' port='5432' user='username' password='password'" country-latest.osm.pbf -nln "country_name_osm_date_" -lco COLUMN_TYPES=other_tags=hstore --config OSM_MAX_TMPFILE_SIZE 1024

But this results in:

Warning 1: Layer creation options ignored since an existing layer is being appended to.

Additionally it gives me geometric type mismatches, and failed copy statements, which makes sense, since -nln I think is trying to write everything to one table, and a PBF file will yield multiple tables.

Doubtless this question has shown how bad my ogr2ogr-fu is. So, how can I designate a specific destination table name in the import statement to avoid future import conflicts?

Additional note: osm2pgsql has the ability to use --prefix argument as noted here: Define table name with osm2pgsql, however, I do not have osm2pgsql available to me and would like to accomplish this with ogr2ogr.

1 Answer 1

3

By default ogr2ogr converts all the layers from the datastore and OSM datastore contains five layers http://www.gdal.org/drv_osm.html. The -nln option can be used for renaming just one layer. It means that if you want to rename the layers you must convert them one by one.

ogr2ogr ... country-latest.osm.pbf points ... -nln my_point_layer
ogr2ogr ... country-latest.osm.pbf lines ... -nln my_line_layer
ogr2ogr ... country-latest.osm.pbf multilinestrings ... -nln my_multilinestring_layer
ogr2ogr ... country-latest.osm.pbf multipolygons ... -nln my_multipolygon_layer
ogr2ogr ... country-latest.osm.pbf other_relations ... -nln my_other_relations_layer
1
  • tested it, success! looks like this could be easily scripted. thanks!
    – auslander
    Commented Apr 9, 2018 at 15:45

Your Answer

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

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