User:Abunai/osdebug

From OpenStreetMap Wiki
Jump to: navigation, search

osdebug.pl is a Perl script that creates a waypoint list for fixing OSM debugs from the fixme tags in a map section (osmcut output) and an OSB Reports file. It generates a GPX file that can be loaded on a GPS receiver and a list of error descriptions to print out. Optionally, a bounding box can be given to reduce the output size.

Bugs: The script doesn't really parse XML, but relies on the particular formats from osmcut and OSB Reports.

Example:

./osdebug.pl muenchen.osm bugs_bayern.gpx 48.05 11.545 48.21 11.74

Sample output

  • BUG1
    Bushaltestelle Missing [Orlando]
  • BUG2
    Wenn das eine Kirche ist, fehlt da ein zusätzlicher Punkt mit passender Kennzeichnung.? [Hasienda]
    Ja, eine Kirche ist das auf jeden Fall. [NoName]
  • NODE1
    bus_routes=fixme; highway=bus_stop; operator=Münchner Verkehrsgesellschaft mbH
  • NODE2
    name=FixMe!!!; amenity=fuel
  • WAY1
    name=FIX ME!!!; highway=residential
  • WAY2
    note=FIXME previously unwayed segment

    Code

    #!/usr/bin/perl -w
    require 'flush.pl';
    
    die "Usage: osdebug.pl map.osm bugs.gpx\n" if @ARGV < 2;
    $osmfile = $ARGV[0];
    $osbfile = $ARGV[1];
    
    $lat1 = 0; $lon1 = 0;
    $lat2 = 90; $lon2 = 90;
    
    if (@ARGV == 6) {
        $lat1 = $ARGV[2];
        $lon1 = $ARGV[3];
        $lat2 = $ARGV[4];
        $lon2 = $ARGV[5];
    }
    
    open GPX, ">debug.gpx";
    open HTM, ">debug.html";
    
    print GPX "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>
    <gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\"
        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
        xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n";
    print HTM "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n<h1>OSM Bug Report</h1><ul>\n";
    
    $b = 0;
    open IN, "<$osbfile";
    while (<IN>) {
        /<wpt lat="([0-9\.]*)" lon="([0-9\.]*)"><desc>OPEN (.*)<\/desc><\/wpt>/ or next;
        $lat=$1; $lon=$2; $txt=$3;
    
        if ($lat > $lat1 and $lat < $lat2 and $lon > $lon1 and $lon < $lon2) {
    	$txt =~ s/:::/<br\/>/g;
    	$b++;
    	print GPX "<wpt lat=\"$lat\" lon=\"$lon\"><desc>BUG$b</desc></wpt>\n";
    	print HTM "<li>BUG$b<br/>$txt\n";
        }
    }
    close IN;
    
    $n=0;
    %ndlat=();
    %ndlon=();
    open NODE, "<$osmfile";
    while (<NODE>) {
        if (/<node id=\"([0-9]*)\" .*lat=\"([0-9\.]*)\" lon=\"([0-9\.]*)\"\/?>/) {
    	$id=$1, $lat=$2, $lon=$3, $tag="";
    	$ndlat{$id} = $lat, $ndlon{$id} = $lon if ($lat > 48 and $lat < 48.25 and $lon > 11.4 and $lon < 11.75);
        }
        $tag .= "$1=$2; " if /<tag k=\"(.*)\" v=\"(.*)\"\/>/ and $1 ne "created_by";
        if (/<\/node>/) {
          $tag =~ s/; $//;
    
          next if not $tag =~ /fix.*me/i;
    
        if ($lat > $lat1 and $lat < $lat2 and $lon > $lon1 and $lon < $lon2) {
    	  $n++;
    	  print GPX "<wpt lat=\"$lat\" lon=\"$lon\"><desc>NODE$n</desc></wpt>\n";
    	  print HTM "<li>NODE$n<br/>$tag\n";
          }
        }
    }
    close NODE;
    
    $n=0;
    $w=1;
    open WAY, "<$osmfile";
    while (<WAY>) {
        $id=$1, $tag="", @nd=() if /<way id=\"([0-9]*)\".*>/;
        $tag .= "$1=$2; " if /<tag k=\"(.*)\" v=\"(.*)\"\/>/ and $1 ne "created_by";
    
        push (@nd, $1) if /<nd ref=\"([0-9]*)\"\/>/;
    
        if (/<\/way>/) {
          $tag =~ s/; $//;
    
          next if not $tag =~ /fix.*me/i;
          next if $tag =~ /boundary=administrative/;
    
          $j=0;
          foreach (@nd) {
    	  $n=$_;
    
    	  next if not $ndlat{$n};
    	  print GPX "<wpt lat=\"$ndlat{$n}\" lon=\"$ndlon{$n}\"><desc>WAY$w</desc></wpt>\n";
    	  $j++;
          }
    
          if ($j) {
    	  print HTM "<li>WAY$w<br/>$tag\n";
    	  $w++;
          }
        }
    }
    close WAY;
    
    print GPX "</gpx>";
    close GPX;