User:Vwb/dupew.pl

From OpenStreetMap Wiki
Jump to: navigation, search
#!/usr/bin/perl
# 
# Localize way over way (segments which belong to more than 1 way)
# use: dupew.pl <file.osm>
#
use XML::Simple;

my $file = $ARGV[0];
my $xs1 = XML::Simple->new(ForceArray => 1,KeepRoot => 1);
my $doc = $xs1->XMLin($file);

my %check = {};

$ways = $doc->{'osm'}->[0]->{'way'};
$doc = {};

#find every way segment
foreach $way (keys %$ways) {                              
  foreach $segment (keys %{$ways->{$way}->{'seg'}}){       
    #and join it with way
    push(@{$check{$segment}},$way);                     
  }   
}

foreach $x (keys %check) {  
  #segments with more than one way
  if (@{$check{$x}} > 1) {                                             
    for $wayid (@{$check{$x}}) {
      $final{$wayid} += 1;
    }
  }
}     

print "Copy & paste into JOSM search:\n";
foreach $id (keys %final) {
  print "id:$id\n";
  for $tag (@{$ways->{$id}->{'tag'}}) {
    print "  ".$tag->{'k'}.":".$tag->{'v'}."\n";    
  }
  print "\n";
}