Skip to content

Instantly share code, notes, and snippets.

@nifgraup
Created December 5, 2010 23:36

Revisions

  1. nifgraup revised this gist Dec 5, 2010. 2 changed files with 29 additions and 1 deletion.
    28 changes: 28 additions & 0 deletions osmnames.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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();
    2 changes: 1 addition & 1 deletion postskrifta.sh
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,4 @@ 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
    done
  2. nifgraup created this gist Dec 5, 2010.
    23 changes: 23 additions & 0 deletions postskrifta.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/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