1

I used ogr2ogr to convert from osm data (pbf) to spatialite :

ogr2ogr -progress -f SQLite -dsco spatialite=yes france.simple.spatialite france-latest.osm.pbf

then, a large part of the imported data misses osm_id

spatialite> select count(*) from multipolygons;
42287946
spatialite> select count(*) from multipolygons where osm_id is null;
42153385

any ideas why, and how to fix this ?

2
  • 2
    I edited the title a bit because this will happen with all outputformats and it affects only the multipolygon table. The background is that osm_id is not unique globally in the native OSM data. Osm_id of ways starts from #1 as well as in the relations table and therefore it is possible to get two polygons with the same osm_id: one from a closed way, another from a multipolygon relation. Unfortunately that makes also osm_id unsuitable as a primary key. User may not notice that because small amounts of data may not contain duplicate osm_ids.
    – user30184
    Commented May 15, 2015 at 6:34
  • osm2pgsql uses negative ids for multipolygon relations and positive ones for closed ways. Would that approach spoil anything?
    – AndreJ
    Commented May 15, 2015 at 10:14

1 Answer 1

2

You are only inspecting osm_id field. It seems you didn't inspect your multipolygons table.

On a local use case, I do :

ogrinfo -so france.simple.spatialite multipolygons

It returns

FID Column = OGC_FID
Geometry Column = GEOMETRY
osm_id: String (0.0)
osm_way_id: String (0.0)
name: String (0.0)
type: String (0.0)
...

So the identifiers are not only located on the osm_id but also in an osm_way_id.

Try :

select count(*) from multipolygons where osm_id is null AND osm_way_id is null;

It should return 0 records.

So, there is no need for fix.

1
  • 2
    Explained as a comment inside the osmconf.ini file: [multipolygons] # common attributes # note: for multipolygons, osm_id=yes instanciates a osm_id field for the id of relations # and a osm_way_id field for the id of closed ways. Both fields are exclusively set. Also related to GDAL ticket trac.osgeo.org/gdal/ticket/5470
    – user30184
    Commented May 15, 2015 at 5:04

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.