QuickOSM icon indicating copy to clipboard operation
QuickOSM copied to clipboard

Import super-relations contained in .osm files

Open Sidapo opened this issue 5 years ago • 10 comments

Is your feature request related to a problem? Please describe

We have .osm files containing many (hiking) routes that are super-relations. We need to import these relations into QGIS for further analysis, but have not found a way to do so. QuickOSM only imports the lowest hierarchy of the relations.

Describe the solution you'd like

It would be great if QuickOSM could import these relations of relations the same way other relations are currently imported (as their own Multilinestring with the key "osm_type"='relation')

Sidapo avatar Mar 19 '19 10:03 Sidapo

It's not going to be an easy task. OSM files are opened by OGR: https://www.gdal.org/drv_osm.html

It's clearly stated that OGR supports only relation type route, multipolygon, boundary. All other relations fail in other_relations layer, which is not loaded by default in QuickOSM.

In QGIS 2, you could use some Processing algorithms to work with these relations. But I didn't get enough time to port them in QGIS 3, see ticket https://github.com/3liz/QuickOSM/issues/146

https://github.com/3liz/QuickOSM/issues/146

Gustry avatar Mar 29 '19 21:03 Gustry

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 07 '19 08:06 stale[bot]

+1. It seems the issue ultimately boils down to the limitations of the OSM database's relational capabilities. Having said that there are surely workarounds that would 'flatten' relations into layers containing all reference features at any depth, much as JOSM's 'Export as GPX' feature does for route relations.

rideearthtom avatar Jun 07 '19 10:06 rideearthtom

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 08 '19 10:06 stale[bot]

QGIS 3.10 seems to be able to import such other relations by drag-and-drop. But all the tags will be included in a other_tags column, this at least can be later corrected using a few commands with regex to created new columns. But the main problem QGIS will only import the first 99 ones!

M-Rick avatar Apr 03 '20 19:04 M-Rick

QGIS 3.10 seems to be able to import such other relations by drag-and-drop

But do you have a geometry? Other type than route, multipolygon, boundary ?

this at least can be later corrected using a few commands with regex to created new columns

Use the Explode HStore algorithm, it will do that for you without any regex.

Gustry avatar Apr 04 '20 07:04 Gustry

QGIS 3.10 seems to be able to import such other relations by drag-and-drop

But do you have a geometry? Other type than route, multipolygon, boundary ?

No I don't, and I don't want one anyway. I want to have a listing of values taken from those relations. I should have more than 4K of them, but I only get 99, it seems to be the very first 99 ones.

this at least can be later corrected using a few commands with regex to created new columns

Use the Explode HStore algorithm, it will do that for you without any regex.

Thank you it did the job.

M-Rick avatar Apr 04 '20 08:04 M-Rick

I made a test exporting in PBF. Surprisingly, QGIS will convert exactly 2575 features in PBF, while it will only convert 99 of them in OSM XML. Strange. 2575 is better than 99, but I am still missing a lot of features from my file.

M-Rick avatar Apr 06 '20 17:04 M-Rick

I got it working by adding this to ogr2ogr.

--config OSM_USE_CUSTOM_INDEXING NO

M-Rick avatar Apr 08 '20 20:04 M-Rick

I come back on this subjects. Could QuickOSM use a shell script to convert in JSON instead to import those kind of relations? That what I have resigned to use. It works better and I use shell scripts with awk and sed commands that do the job perfectly well. Maybe QuickOSM could include the same with the script being written by the settings the user will choose? With this process you can even keep, on not, roles or segments if they are some. With this simple script, you can keep for example only the route_master relations. It will keep all the items included between the <relation>…</relation> tags.

cat my_file.osm | \
sed -e 's/^[ \t]*//' | \
name="k='type' v='route_master'" \
awk -v name="$name" '$0 ~ ENVIRON["name"] {print "<relation" $0 "</relation>"}' RS="<relation|</relation>"

M-Rick avatar Aug 22 '23 20:08 M-Rick