Skip to content

Instantly share code, notes, and snippets.

@ImreSamu
Last active August 29, 2015 14:05
Show Gist options
  • Save ImreSamu/be49fd1ce511975325d2 to your computer and use it in GitHub Desktop.
Save ImreSamu/be49fd1ce511975325d2 to your computer and use it in GitHub Desktop.
query the first contributor who added bridge=swing to the way - and generate Overpass-Turbo Wizard Query
#
# Ubuntu 14.04 linux
# This example file is released into the Public Domain. ( ImreSamu 2014.08.29 )
#
## Warning! - draft code! it creates lot of temp file to the working directory.
#
#### The Job ###############################
#* find all bridge=swing ( now 639 results : http://taginfo.openstreetmap.org/search?q=bridge%3Dswing )
# *split results by the first contributor who added bridge=swing to the way
# *get the results into overpass-turbo wizard format and you can copy/paste to overpass-turbo.eu Wizard
# *from overpass-turbo , you can ( Export/Data/"Load data into an OSM editor: JOSM," ) ( for examination and editing )
#
#### the Result ( but only for the ways ) ###########################
#
# https://gist.github.com/ImreSamu/a2dd0a8c25f0fea5284c#file-bridge_swing_overpass_wizard-md
#
#### Prerequisites ###############
#
# Osmium Tool for - OSM OPL ("Object Per Line") Format
# "This format was created to allow easy access to and manipulation of OSM data with typical UNIX command line tools such as grep, # "sed, and awk. This can make some ad-hoc OSM data manipulation easy to do, but is probably not as fast as some specialized tool. # "But it beats grepping in XML files... "
# more informations and examples:
# http://osmcode.org/libosmium/manual/libosmium-manual.html#output-formats
# https://www.sotm-eu.org/en/slots/36
# https://www.sotm-eu.org/slides/44.pdf
#
#
mkdir ...(empty) temp directory ....
cd ...(empty) temp directory ....
#
#
# find all bridge=swing ( now 639 results : http://taginfo.openstreetmap.org/search?q=bridge%3Dswing )
# and convert to OSM OPL format
# check: http://wiki.openstreetmap.org/wiki/Overpass_API/XAPI_Compatibility_Layer
# and please use [bbox=...] parameter - for Bounding Boxes
#
wget -O bridge_swing.osm 'http://www.overpass-api.de/api/xapi_meta?way[bridge=swing]'
cat bridge_swing.osm
osmium cat bridge_swing.osm -f opl > bridge_swing.opl
# Find all IDs of ways tagged bridge=swing
# it is now working for thes way , but there are other points and realations tagged with this key-value
# check: http://taginfo.openstreetmap.org/tags/bridge=swing
#
egrep '^w' bridge_swing.opl | egrep "( T|,)bridge=swing" | cut -d' ' -f1 | cut -c2- > bridge_swing_ids.txt
# query the history for every OSM Id.
#
# generate code for all IDs like:
# wget -O w99211716.osm 'http://api.openstreetmap.org/api/0.6/way/99211716/history'
#
awk '{ print "wget -O w" $1 ".osh '"'"'http://api.openstreetmap.org/api/0.6/way/" $1 "/history'"'"'" }' bridge_swing_ids.txt > get_oshistory.sh
parallel -j8 -a get_oshistory.sh
#
# convert the osm history file to OPL ( osmium cat w11323607.osh -f opl )
# sample OSM History OPL file:
# w100646626 v1 dV c7343540 t2011-02-20T15:08:57Z i37137 uDerick%0020Rethans Tbridge=yes,highway=footway Nn309461645,n1163494643
# w100646626 v2 dV c12447614 t2012-07-23T09:52:38Z i404175 urickogden Tbridge=swing,highway=footway Nn309461645,n1163494643
# w100646626 v3 dV c18538313 t2013-10-25T16:16:57Z i24119 uMauls Tbridge=swing,highway=footway Nn309461645,n2508499967
# w100646626 v4 dV c25024407 t2014-08-26T10:51:45Z i66391 ugeozeisig Tbridge=movable,bridge:movable=swing,highway=footway Nn309461645,n2508499967
# w100646626 v5 dV c25050883 t2014-08-27T12:42:02Z i66391 ugeozeisig Tbridge=swing,highway=footway Nn309461645,n2508499967
#
# filter the results by the first contributor who added bridge=swing to the way ( egrep -m 1 '( T|,)bridge=swing' )
#result: v2
# w100646626 v2 dV c12447614 t2012-07-23T09:52:38Z i404175 urickogden Tbridge=swing,highway=footway Nn309461645,n1163494643
#
#
# generate code for all IDs like:
# echo 11323607 & osmium cat w11323607.osh -f opl | egrep -m 1 '( T|,)bridge=swing' > w11323607.fed_opl
#
awk '{ print "echo " $1 " & osmium cat w" $1 ".osh -f opl | egrep -m 1 '"'"'( T|,)bridge=swing'"'"' > w" $1 ".fed_opl" }' bridge_swing_ids.txt > get_first_edit.sh
rm *.fed_opl
parallel -j8 -a get_first_edit.sh
#
# generate overpass-turbo Wizard query to every user to bridge_swing_overpass_wizard2.md
# syntax: http://wiki.openstreetmap.org/wiki/Overpass_turbo/Wizard -> see "Meta-Data Filters"
#
# like:
# ## osm-user
# type:way and ( id:27001207 or id:72584563 ) global
#
cat *.fed_opl | cut -d' ' -f7 | cut -c2- | sort | uniq | while read ln; do xuser=$ln && echo $'\n\n\n\n' "## $xuser " $'\n\n' && cat *.fed_opl | egrep "( u)$xuser" | cut -d' ' -f1 | cut -c2- | awk 'BEGIN{ORS=""; print "type:way and ( " } { print "id:" $1 " or "}END{print "id:1) global \n" }' ; done > bridge_swing_overpass_wizard2.md
#
# some text formatting ;
#
sed -i 's/or id:1)/)/g' bridge_swing_overpass_wizard2.md
sed -i 's/ ##/##/g' bridge_swing_overpass_wizard2.md
# check the result :
cat bridge_swing_overpass_wizard2.md
# How to check the query
# * go http://overpass-turbo.eu/
# * select "Wizard"
# * copy /paste the generated query : " type:way and ( id:27001207 or id:72584563 ) global"
# * "Build and run query" -> and check the result.
# * if you get timeout error, then check the generated script timeout ( "<osm-script output="json" timeout="25">" ) and set to 200
# * you can "load data into an OSM editor: JOSM," - see "Export" menu
# -----
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment