Created
December 5, 2010 23:36
-
-
Save nifgraup/729601 to your computer and use it in GitHub Desktop.
Script to list streets in Iceland based on their postal code and another to list streets in Iceland. Will later combine those to check what streets in Iceland are missing.
This file contains hidden or 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
#!/usr/bin/perl | |
# Author: Björgvin Ragnarsson | |
# License: Public Domain | |
use OSM::osm; # PERL osm module by gary68 | |
openOsmFile('Iceland.osm'); | |
skipNodes(); | |
($wayId, $wayUser, $aRef1, @tags) = getWay(); | |
while ($wayId != -1) | |
{ | |
for($i = 0; exists $tags[0][$i]; $i++) | |
{ | |
$key = substr($tags[0][$i], 0, 4); | |
$val = substr($tags[0][$i], 5); | |
if($key eq 'name') | |
{ | |
print $val; | |
last; | |
} | |
} | |
print "\n"; | |
($wayId, $wayUser, $aRef1, @tags) = getWay(); | |
} | |
closeOsmFile(); |
This file contains hidden or 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 | |
# Author: Björgvin Ragnarsson | |
# License: Public Domain | |
encoding="UTF-8" # annað algengt: "ISO_8859-1" | |
if [ "$1" = "--list-towns" ]; then | |
awk 'BEGIN{FS=";"}{print $2}' postnumer.txt | uniq | iconv -f ISO_8859-1 -t $encoding | |
exit | |
elif [ "$1" = "--town" ]; then | |
postalcodes=`cat postnumer.txt | iconv -f ISO_8859-1 -t $encoding | grep $2 | awk 'BEGIN{FS=";"}{print $1}'` | |
elif [ "$1" = "--codes" ]; then | |
postalcodes=$2 | |
else | |
echo "Usage:" | |
echo " $0 --list-towns | --codes ""LIST_OF_POSTAL_CODES"" | --town TOWN" | |
exit | |
fi | |
for n in $( echo $postalcodes ); do | |
cat gotuskra.txt | iconv -f ISO_8859-1 -t $encoding | awk -v n="$n" 'BEGIN{FS=";"}{if ($2 == n) print $3}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment