Created
February 13, 2014 03:47
-
-
Save MrDOS/8969402 to your computer and use it in GitHub Desktop.
OML way to latitude/longitude pair conversion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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