From b6ddad9a4012a5cacc605f223cae520a2830d7bb Mon Sep 17 00:00:00 2001 From: martin-s Date: Tue, 1 Jul 2008 09:52:03 +0000 Subject: 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 --- navit/script/osm/osmtool.pl | 126 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 navit/script/osm/osmtool.pl (limited to 'navit/script/osm/osmtool.pl') 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); -- cgit v1.2.1