[GIS] How to search within a string to extract data from OSM other_tags

openstreetmapqgisquery

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'

Best Answer

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/

Related Question