Skip to content

Instantly share code, notes, and snippets.

@MrDOS
Created February 13, 2014 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrDOS/8969402 to your computer and use it in GitHub Desktop.
Save MrDOS/8969402 to your computer and use it in GitHub Desktop.
OML way to latitude/longitude pair conversion.
#! /bin/sh
# Convert an OSM way to a set of latitude/longitude pairs. Assumes only one way
# in input.
NODE_PATTERN='<nd ref="\([0-9]\+\)"\/>'
COORD_PATTERN='\-\?[0-9.]\+'
LAT_PATTERN='lat="'"$COORD_PATTERN"'"'
LON_PATTERN='lon="'"$COORD_PATTERN"'"'
if [ $# -eq 0 ]
then
echo "Usage: $0 http://www.openstreetmap.org/api/0.6/way/<way>" 1>&2
exit 1
fi
wget -q "$1" -O - | while read line
do
if echo "$line" | grep -q "$NODE_PATTERN"
then
node_id=`echo "$line" | sed -e 's/'"$NODE_PATTERN"'/\1/'`
node=`wget -q "http://www.openstreetmap.org/api/0.6/node/$node_id" -O -`
lat=`echo "$node" | grep -o "$LAT_PATTERN" | grep -o "$COORD_PATTERN"`
lon=`echo "$node" | grep -o "$LON_PATTERN" | grep -o "$COORD_PATTERN"`
echo "$lat $lon"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment