2

I am working with OSM data in QGIS and I often need to query items in the other tags field. When I download the data using the OSM download plugin the other tags come in one field so are not easy to use.

Currently I am looking at permissive paths etc

"foot"=>"permissive","horse"=>"permissive","tracktype"=>"grade2"

I can use the expression (badly written) below to pull out what I want and perform a selection but it is a headache. any better ideas? I have tried quick OSM but that doesn't seem to have access to the details in the other tags

substr( substr( "other_tags" , strpos( "other_tags",'foot"=>') ,70),10,strpos( substr( substr( "other_tags" , strpos( "other_tags",'foot"=>') ,70),10,20),'","')) = 'permissive'

5

I'd suggest an alternative approach: Download raw OSM data and use OGR to prepare your data in such a way that the relevant tags are not mashed together in the "other_tags" column. This can be achieved by customizing OGR's osmconf.ini file as documented in http://www.gdal.org/drv_osm.html.

Look for the lines

# keys to report as OGR fields
attributes=name,highway,waterway,aerialway,barrier,man_made

and add your keys such as foot, horse, and tracktype.

Then you can, for example, create a Spatialite database using ogr2ogr

>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat 2.59 46.58 -1.44 47.07 noirmoutier.db noirmoutier.pbf

as described in http://anitagraser.com/2014/05/31/a-guide-to-googlemaps-like-maps-with-osm-in-qgis/

1
  • 2
    After this pointing me in the right direction I used import to xml and export to spatialLite (from OSM menu in qgis) where I could select all the wonderful tags I fancied.
    – Sethinacan
    Jun 8 '15 at 11:55
2

I would recommend to extract all relevant ways from Overpass API using regular expressions. Here's an example which returns only ways with a permissive value in any key in the current bbox.

[bbox:{{bbox}}];
way[~"."~"^permissive$"];
(._;>;);
out meta;

Overpass Turbo Link: http://overpass-turbo.eu/s/9ML (Hit "Run" to test)

You can use pretty much the same syntax from within QuickOSM as well.

2
  • That looks handy but the syntax is a bit beyond me
    – Sethinacan
    Jun 8 '15 at 11:49
  • It's really not that difficult: Line 1: Restrict ways to current bounding box. Line 2: Just select ways, which have "permissive" in any of its keys. This would match e.g. foot=permissive, or horse=permissive. Line 3: Return ways along with their nodes (to get all lat/lon details as well). Line 4: Return all data including meta data (version, timestamp, etc.). I hope this clarifies the syntax a bit. Give it a try in QuickOSM.
    – mmd
    Jun 8 '15 at 17:36
2

Since QGIS 3.6, you can use Explode HStore field algorithm in Processing Toolbox. This algorithm will explode your HStore field into many fields. There is also support for HStore expression in QGIS since QGIS 3.4.

Before QGIS 3.6, you can also use the QuickOSM plugin in QGIS. You can open a local OSM file and get all keys as a column. QuickOSM will split the "other_tags" column as you want.

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.