/[zanavi_public1]/navit/navit/script/osm/osmtool.pl
ZANavi

Contents of /navit/navit/script/osm/osmtool.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 2203 byte(s)
import files
1 #! /usr/bin/perl
2 use Geo::OSM::APIClientV6;
3 use Data::Dumper;
4
5 sub print_error
6 {
7 print Dumper($api->{last_error});
8 print 'Error:' . $api->{last_error}->rc . "\n";
9 }
10
11 sub print_entitiy
12 {
13 my ($res)=@_;
14
15 my ($xml);
16 $xml=$res->xml;
17 $xml=~s/>/>\n/g;
18 print $xml;
19 }
20
21 sub remove_member
22 {
23 my ($res,$type,$id)=@_;
24
25 my (@members);
26 my $found=0;
27 foreach my $member (@{$res->members}) {
28 if ($member->member_type eq $type && $member->ref eq $id) {
29 $found++;
30 } else {
31 push(@members, $member);
32 }
33 }
34 if ($found) {
35 $res->set_members(\@members);
36 }
37 return $found;
38 }
39
40 sub cmd_delete
41 {
42 my($type,$id)=@_;
43 my($res);
44 $res=$api->get($type,$id);
45 if (!$api->create_changeset()) {
46 print_error();
47 return 1;
48 }
49 if (!$api->delete($res)) {
50 print_error();
51 return 1;
52 }
53 if (!$api->close_changeset()) {
54 print_error();
55 return 1;
56 }
57 return 0;
58 }
59
60 sub cmd_get
61 {
62 my($type,$id)=@_;
63
64 my($res,$xml);
65 $res=$api->get($type,$id);
66 print_entitiy($res);
67 }
68
69 sub cmd_relations
70 {
71 my($type,$id)=@_;
72
73 my($res,$xml);
74 $res=$api->get($type,$id,"relations");
75 print_entitiy($res);
76 }
77
78 sub cmd_remove_member_all
79 {
80 my($type,$id)=@_;
81
82 my($res);
83 $res=$api->get($type,$id,"relations");
84 if (!remove_member($res,$type,$id)) {
85 print "Error:Member not found\n";
86 return 1;
87 }
88 if (!$api->modify($res)) {
89 print_error();
90 return 1;
91 }
92 return 0;
93 }
94
95 sub cmd_reload
96 {
97 my($type,$id)=@_;
98 $res=$api->get($type,$id);
99 if (!$api->create_changeset()) {
100 print_error();
101 return 1;
102 }
103 if (!$api->modify($res)) {
104 print_error();
105 return 1;
106 }
107 if (!$api->close_changeset()) {
108 print_error();
109 return 1;
110 }
111 return 0;
112 }
113
114 sub command
115 {
116 my(@arg)=@_;
117
118 if ($arg[0] eq 'delete') {
119 cmd_delete($arg[1],$arg[2]);
120 }
121 if ($arg[0] eq 'get') {
122 cmd_get($arg[1],$arg[2]);
123 }
124 if ($arg[0] eq 'relations') {
125 cmd_relations($arg[1],$arg[2]);
126 }
127 if ($arg[0] eq 'remove-member-all') {
128 cmd_remove_member_all($arg[1],$arg[2]);
129 }
130 if ($arg[0] eq 'reload') {
131 cmd_reload($arg[1],$arg[2]);
132 }
133 }
134
135 while (substr($ARGV[0],0,2) eq '--') {
136 $expr=substr($ARGV[0],2);
137 ($key,$value)=split('=',$expr,2);
138 $attr{$key}=$value;
139 shift;
140 }
141 $api=new Geo::OSM::APIClient(api=>'http://www.openstreetmap.org/api/0.6',%attr);
142 command(@ARGV);

Properties

Name Value
svn:executable *

   
Visit the ZANavi Wiki