diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-07-01 09:52:03 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2008-07-01 09:52:03 +0000 |
commit | b6ddad9a4012a5cacc605f223cae520a2830d7bb (patch) | |
tree | cce1813638caa702bef1a87ce979907782fa6db7 /navit/script | |
parent | 17d842618efc7aca3ca95828e8ef5345add0567a (diff) | |
download | navit-b6ddad9a4012a5cacc605f223cae520a2830d7bb.tar.gz |
Add:script:Added new script osmtool.pl, improved border_follower
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1186 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/script')
-rwxr-xr-x | navit/script/osm/border_follower.pl | 36 | ||||
-rwxr-xr-x | navit/script/osm/osmtool.pl | 126 |
2 files changed, 151 insertions, 11 deletions
diff --git a/navit/script/osm/border_follower.pl b/navit/script/osm/border_follower.pl index 4512bfd50..b19472878 100755 --- a/navit/script/osm/border_follower.pl +++ b/navit/script/osm/border_follower.pl @@ -8,6 +8,11 @@ # ./border_follower.pl 10359135 Germany 2 country state use Geo::OSM::APIClientV5; use Data::Dumper; +$direction='left'; +if ($ARGV[0] eq '-r') { + $direction='right'; + shift(@ARGV); +} $first_wayid=$ARGV[0]; $name=$ARGV[1]; $required_admin_level=$ARGV[2]; @@ -21,12 +26,12 @@ sub error { my ($message)=@_; $node=$api->get_node($last); - print "$message at $last $node->{lat} $node->{lon}\n"; + print "$message at Node $last $node->{lat} $node->{lon}\n"; $latl=$node->{lat}-0.01; $lath=$node->{lat}+0.01; $lonl=$node->{lon}-0.01; $lonh=$node->{lon}+0.01; - system("wget -O error.osm http://www.openstreetmap.org/api/0.5/map?bbox=$lonl,$latl,$lonh,$lath ; java -jar ~/map/osm/josm/josm-latest.jar error.osm --selection=id:$last"); + system("wget -O error.osm http://www.openstreetmap.org/api/0.5/map?bbox=$lonl,$latl,$lonh,$lath ; josm error.osm --selection=id:$last"); exit(1); } @@ -40,7 +45,7 @@ do { $reverse=0; # print Dumper($tags); while( my($k,$v) = splice @{$tags}, 0, 2 ) { - if (($k eq "left:$type" || $k eq "left:$alt_type") && $v eq $name) { + if (($k eq "$direction:$type" || $k eq "$direction:$alt_type") && $v eq $name) { $reverse=1; } } @@ -64,21 +69,26 @@ do { $count=0; foreach $way (@$ways) { $newid=$way->{'id'}; - print "Way $newid\n"; + $timestamp=$way->{'timestamp'}; + if ($newid == $lastid) { + next; + } + $nodes=$way->nodes; + print "way $newid ($#$nodes nodes) $timestamp\n"; my $tags = $way->tags; $match=0; $boundary=0; $admin_level=0; while( my($k,$v) = splice @{$tags}, 0, 2 ) { print "tag: $k=$v\n"; - if (($k eq "left:$type" || $k eq "right:$type") && $newid != $lastid) { + if (($k eq "left:$type" || $k eq "right:$type")) { if ($v eq $name) { $match=1; } else { $neighbors{$v}=$newid; } } - if (($k eq "left:$alt_type" || $k eq "right:$alt_type") && $v eq $name && $newid != $lastid) { + if (($k eq "left:$alt_type" || $k eq "right:$alt_type") && $v eq $name) { print "Warning: $k in $newid\n"; $match=1; } @@ -97,8 +107,8 @@ do { } } } - print "match=$match\n"; if ($match) { + print "MATCH\n"; if ($boundary != 1 ) { print "boundary $boundary wrong at $newid\n" } @@ -109,10 +119,14 @@ do { $count++; } } - if ($count != 1) { - error "Count: $count != 1" - } else { - $path="$path $wayid"; + if ($count == 0) { + error "No connection" + } else { + if ($count > 1) { + error "Multiple connections ($count)" + } else { + $path="$path $wayid"; + } } } while ($wayid != $first_wayid); print "End reached\n"; diff --git a/navit/script/osm/osmtool.pl b/navit/script/osm/osmtool.pl new file mode 100755 index 000000000..30a443fb6 --- /dev/null +++ b/navit/script/osm/osmtool.pl @@ -0,0 +1,126 @@ +#! /usr/bin/perl +use Geo::OSM::APIClientV5; +use Data::Dumper; + +sub print_error +{ + print Dumper($api->{last_error}); + print 'Error:' . $api->{last_error}->rc . "\n"; +} + +sub print_entitiy +{ + my ($res)=@_; + + my ($xml); + $xml=$res->xml; + $xml=~s/>/>\n/g; + print $xml; +} + +sub remove_member +{ + my ($res,$type,$id)=@_; + + my (@members); + my $found=0; + foreach my $member (@{$res->members}) { + if ($member->member_type eq $type && $member->ref eq $id) { + $found++; + } else { + push(@members, $member); + } + } + if ($found) { + $res->set_members(\@members); + } + return $found; +} + +sub cmd_delete +{ + my($type,$id)=@_; + my($res); + $res=$api->get($type,$id); + if (!$api->delete($res)) { + print_error(); + return 1; + } + return 0; +} + +sub cmd_get +{ + my($type,$id)=@_; + + my($res,$xml); + $res=$api->get($type,$id); + print_entitiy($res); +} + +sub cmd_relations +{ + my($type,$id)=@_; + + my($res,$xml); + $res=$api->get($type,$id,"relations"); + print_entitiy($res); +} + +sub cmd_remove_member_all +{ + my($type,$id)=@_; + + my($res); + $res=$api->get($type,$id,"relations"); + if (!remove_member($res,$type,$id)) { + print "Error:Member not found\n"; + return 1; + } + if (!$api->modify($res)) { + print_error(); + return 1; + } + return 0; +} + +sub cmd_reload +{ + my($type,$id)=@_; + $res=$api->get($type,$id); + if (!$api->modify($res)) { + print_error(); + return 1; + } + return 0; +} + +sub command +{ + my(@arg)=@_; + + if ($arg[0] eq 'delete') { + cmd_delete($arg[1],$arg[2]); + } + if ($arg[0] eq 'get') { + cmd_get($arg[1],$arg[2]); + } + if ($arg[0] eq 'relations') { + cmd_relations($arg[1],$arg[2]); + } + if ($arg[0] eq 'remove-member-all') { + cmd_remove_member_all($arg[1],$arg[2]); + } + if ($arg[0] eq 'reload') { + cmd_reload($arg[1],$arg[2]); + } +} + +while (substr($ARGV[0],0,2) eq '--') { + $expr=substr($ARGV[0],2); + ($key,$value)=split('=',$expr,2); + $attr{$key}=$value; + shift; +} +$api=new Geo::OSM::APIClient(api=>'http://www.openstreetmap.org/api/0.5',%attr); +command(@ARGV); |