--- /dev/null
+#!/usr/bin/perl
+use Data::Dumper;
+sub deg
+{
+ my ($deg, $dir)=(@_);
+
+ my ($in,$degi);
+
+ $in=$deg;
+ $degi=int($deg);
+ $deg-=$degi;
+ $deg*=60;
+ return sprintf("%d%09.6f %s", $degi, $deg, $dir);
+}
+sub coord
+{
+ my ($id)=(@_);
+ return deg($lat{$id}, "N") . " " . deg($lon{$id}, "E");
+}
+
+while (<>) {
+ $line = $_;
+ chomp($line);
+ #print "$line\n";
+ if ($line =~ /<node id="(.*?)" lat="(.*?)" lon="(.*?)"/) {
+ $lat{ $1 } = $2;
+ $lon{ $1 } = $3;
+ %tag=();
+ } elsif ($line =~ /<segment id="(.*?)" from="(.*?)" to="(.*?)"/) {
+ $from{ $1 } = $2;
+ $to{ $1 } = $3;
+ $reference{ $1 } =0;
+ %tag=();
+ } elsif ($line =~ /<tag k="(.*?)" v="(.*?)"/) {
+ if ($1 ne "created_by" && $1 ne "converted_by") {
+ $tag{ $1 } = $2;
+ }
+ } elsif ($line =~ /<way id="(.*?)"/) {
+ %tag=();
+ $coords="";
+ $in_way=1;
+ $way_id=$1;
+ $start='';
+ $end='';
+ } elsif ($line =~ /<seg id="(.*?)"/) {
+ if ($in_way) {
+ $from=coord($from{ $1 });
+ $to=coord($to{ $1 });
+ $reference{ $1 }++;
+ if ($start eq '') {
+ $start=$from;
+ $end=$to;
+ $coords="$start\n$end\n";
+ $start="dummy";
+ $end="dummy";
+ } else {
+ if ($start == $from) {
+ $coords="$to\n" . $coords;
+ $start=$to;
+ } elsif ($start == $to) {
+ $coords="$from\n" . $coords;
+ $start=$from;
+ } elsif ($end == $from) {
+ $coords.=$to . "\n";
+ $end=$to;
+ } elsif ($end == $to) {
+ $coords.=$from . "\n";
+ $end=$from;
+ } else {
+ push(@coords,$coords);
+ $start=$from;
+ $end=$to;
+ $coords="$start\n$end\n";
+ $start="dummy";
+ $end="dummy";
+ # print STDERR "not connected from=$from to=$to coords=$coords \n";
+ }
+ }
+ }
+ } elsif ($line =~ /<osm /) {
+ } elsif ($line =~ /<?xml /) {
+ } elsif ($line =~ /<\/node/) {
+ if (%tag) {
+ #print STDERR Dumper(\%tag);
+ }
+ } elsif ($line =~ /<\/segment/) {
+ if (%tag) {
+ #print STDERR Dumper(\%tag);
+ }
+ } elsif ($line =~ /<\/segment/) {
+ } elsif ($line =~ /<\/way/) {
+ $type='street_unkn';
+ if ($tag{'highway'} ne '') {
+ for ($tag{'highway'}) {
+ if (/cycleway/ || /footway/ || /steps/ || /cyclepath/ || /track/ || /service/ || /pedestrian/) {
+ $type='street_nopass';
+ } elsif (/residential/ || /unclassified/) {
+ $type='street_1_city';
+ } elsif (/tertiary/) {
+ $type='street_2_city';
+ } elsif (/secondary/) {
+ $type='street_3_city';
+ } elsif (/primary/) {
+ $type='street_4_city';
+ } elsif (/motorway/) {
+ $type='highway_city';
+ } else {
+ print STDERR "Unknown highway $_\n";
+ }
+
+ }
+ }
+ if ($tag{'natural'} ne '') {
+ for ($tag{'natural'}) {
+ if (/water/) {
+ $type='water_poly';
+ } else {
+ print STDERR "Unknown natural $_\n";
+ }
+
+ }
+ }
+ if ($tag{'railway'} ne '') {
+ for ($tag{'railway'}) {
+ if (/rail/) {
+ $type='rail';
+ } else {
+ print STDERR "Unknown railway $_\n";
+ }
+
+ }
+ }
+ if ($tag{'waterway'} ne '') {
+ for ($tag{'waterway'}) {
+ if (/canal/) {
+ $type='water_line';
+ } else {
+ print STDERR "Unknown waterway $_\n";
+ }
+
+ }
+ }
+ if ($tag{'amenity'} ne '') {
+ for ($tag{'amenity'}) {
+ if (/hospital/) {
+ $type='hospital_poly';
+ } elsif (/parking/) {
+ $type='parking_lot_poly';
+ } else {
+ print STDERR "Unknown amenity $_\n";
+ }
+
+ }
+ }
+ if ($tag{'landuse'} ne '') {
+ for ($tag{'landuse'}) {
+ if (/cemetery/) {
+ $type='cemetery_poly';
+ } elsif (/forest/||/village_green/||/greenfield/||/farm/) {
+ $type='wood';
+ } elsif (/industrial/ || /residential/) {
+ $type='industry_poly';
+ } elsif (/parking/) {
+ $type='parking_lot_poly';
+ } elsif (/water/) {
+ $type='water_poly';
+ } else {
+ print STDERR "Unknown landuse $_\n";
+ }
+
+ }
+ }
+ $oline="type=$type";
+ if ($tag{'name'} ne '') {
+ $oline.=' label="' . $tag{'name'} . '"';
+ }
+ $oline .= ' debug="way_id=' . $way_id . ' ';
+ while (($key,$value)=each(%tag)) {
+ $oline .= "$key='$value' ";
+ }
+ $oline .= "\"\n";
+ push(@coords,$coords);
+ foreach $coords (@coords) {
+ print $oline;
+ print $coords;
+ }
+ @coords=();
+ } elsif ($line =~ /<\/osm/) {
+ } else {
+ print "$line\n";
+ }
+ if ($count++ > 5) {
+ #exit(0);
+ }
+}
+while (($key,$value)=each(%reference)) {
+ if ($value != 1) {
+ print STDERR "$key $value\n";
+ }
+}
+