source: subversion/editors/osmpedit/test @ 1099

Last change on this file since 1099 was 1099, checked in by tpersson, 14 years ago

adding support for ways in osmutil.pm

File size: 6.2 KB
Line 
1#    Copyright (C) 2005 Tommy Persson, tpe@ida.liu.se
2#
3#    This program is free software; you can redistribute it and/or modify
4#    it under the terms of the GNU General Public License as published by
5#    the Free Software Foundation; either version 2 of the License, or
6#    (at your option) any later version.
7#
8#    This program is distributed in the hope that it will be useful,
9#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#    GNU General Public License for more details.
12#
13#    You should have received a copy of the GNU General Public License
14#    along with this program; if not, write to the Free Software
15#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
16
17use strict;
18use osmutil;
19
20use vars qw ($opt_getnode $opt_getnodehistory $opt_createnode $opt_deletenode
21             $opt_getseg $opt_getseghistory $opt_createseg $opt_deleteseg
22             $opt_getsegways $opt_getsegareas
23             $opt_getway $opt_getwayhistory $opt_createway $opt_deleteway
24             $opt_from
25             $opt_to $opt_passwd $opt_user
26             $opt_nodetagupdate $opt_getmap);
27
28use Getopt::Mixed;
29Getopt::Mixed::getOptions("getseg=s getseghistory=s createseg deletesegment=s
30                           getsegways=s getsegareas=s
31                           getnode=s getnodehistory=s createnode deletenode=s
32                           getway=s getwayhistory=s createway deleteway=s
33                           from=s to=s
34                           passwd=s user=s
35                           nodetagupdate getmap");
36
37
38my $username = $opt_user;
39my $password = $opt_passwd;
40my $lat = 58.408306;
41my $lon = 15.558601;
42
43my $lat0 = 58.38626835; #North/south
44my $lat1 = 58.43626835;
45my $lon0 = 15.54252335; #east/west
46my $lon1 = 15.64252335;
47
48
49if (defined $opt_getmap) {
50    my $data = curl::grab_osm ($lon0, $lat0, $lon1, $lat1,
51                               $username, $password);
52    print "$data\n";
53    exit 0;
54}
55
56
57if (defined $opt_createnode) {
58    my $uid = osmutil::create_node ($lat, $lon, $username, $password);
59    print STDERR "UID: $uid\n";
60    exit 0;
61}
62
63if (defined $opt_deletenode) {
64    my $resp = osmutil::delete_node ($opt_deletenode, $username, $password);
65    print STDERR "DELETE: $resp\n";
66    exit 0;
67}
68
69if (defined $opt_getnode) {
70    my $node = osmutil::get_node ($opt_getnode, $username, $password);
71    print "NODE: $node\n";
72    exit 0;
73}
74
75if (defined $opt_getnodehistory) {
76    my $node = osmutil::get_node_history ($opt_getnodehistory, $username, $password);
77    print "NODE: $node\n";
78    exit 0;
79}
80
81
82if (defined $opt_getseg) {
83    my $s = osmutil::get_segment ($opt_getseg, $username, $password);
84    print "SEGMENT: $s\n";
85    exit 0;
86}
87
88if (defined $opt_getseghistory) {
89    my $s = osmutil::get_segment_history ($opt_getseghistory, $username, $password);
90    print "SEGMENT: $s\n";
91    exit 0;
92}
93
94if (defined $opt_getsegways) {
95    my $s = osmutil::get_segment_ways ($opt_getsegways, $username, $password);
96    print "SEGMENT $opt_getsegways WAYS: $s\n";
97    exit 0;
98}
99
100if (defined $opt_getsegareas) {
101    my $s = osmutil::get_segment_areas ($opt_getsegareas, $username, $password);
102    print "SEGMENT $opt_getsegways AREAS: $s\n";
103    exit 0;
104}
105
106
107if (defined $opt_createseg) {
108    if (not defined $opt_from) {
109        print STDERR "--from must be defined\n";
110        exit 1;
111    }
112    if (not defined $opt_to) {
113        print STDERR "--to must be defined\n";
114        exit 1;
115    }
116    my $resp = osmutil::create_segment ($opt_from, $opt_to, $username,
117                                        $password);
118    print "Segment created: $resp\n";
119    exit 0;
120}
121
122if (defined $opt_deleteseg) {
123    my $uid = $opt_deleteseg;
124    my $resp = osmutil::delete_segment ($uid, $username, $password);
125    if (not $resp) {
126        print "DELETE FAILED: $uid\n";
127    } else {
128        print "Segment $uid deleted\n";;
129    }
130    exit 0;
131}
132
133
134
135if (defined $opt_getway) {
136    my $s = osmutil::get_way ($opt_getway, $username, $password);
137    print "WAY: $s\n";
138    exit 0;
139}
140
141if (defined $opt_getwayhistory) {
142    my $s = osmutil::get_way_history ($opt_getwayhistory, $username, $password);
143    print "WAY: $s\n";
144    exit 0;
145}
146
147if (defined $opt_createway) {
148    my $resp = osmutil::create_way ($username, $password);
149    print "Way created: $resp\n";
150    exit 0;
151}
152
153if (defined $opt_deleteway) {
154    my $uid = $opt_deleteway;
155    my $resp = osmutil::delete_way ($uid, $username, $password);
156    if (not $resp) {
157        print "DELETE FAILED: $uid\n";
158    } else {
159        print "Way $uid deleted\n";;
160    }
161    exit 0;
162}
163
164if (defined $opt_nodetagupdate) {
165
166    #
167    # Does not work, old method
168    #
169
170    my $uid = osmutil::create_node ($lat, $lon, "", $username, $password);
171    print STDERR "UID: $uid\n";
172
173    if ($uid < 0) {
174        print STDERR "Failure creating node\n";
175        exit 0;
176    }
177   
178    my $node = osmutil::get_node ($uid, $username, $password);
179    print STDERR "NODE: $node\n";
180   
181    if (not osmutil::update_node ($uid, $lat, $lon, "name=Tommy1;",
182                                  $username, $password)) {
183        print STDERR "Update failed\n";
184    }
185   
186    $node = osmutil::get_node ($uid, $username, $password);
187    print STDERR "UPDATED NODE 1: $node\n";
188   
189    if (not osmutil::update_node ($uid, $lat, $lon, "name=Tommy2;",
190                                  $username, $password)) {
191        print STDERR "Update failed\n";
192    }
193   
194    my $node = osmutil::get_node ($uid, $username, $password);
195    print STDERR "UPDATED NODE 2: $node\n";
196   
197#    if (not osmutil::update_node_tags ($uid, "name=Tommy3;",
198#                                      $username, $password)) {
199#       print STDERR "Update tags failed\n";
200#    }
201   
202#    my $node = osmutil::get_node ($uid, $username, $password);
203#    print STDERR "UPDATED NODE 3: $node\n";
204   
205   
206    my $resp = osmutil::delete_node ($uid, $username, $password);
207    if (not $resp) {
208        print "DELETE FAILED: $uid\n";
209    } else {
210        print "Node $uid deleted\n";;
211    }
212    exit 0;
213}
214
215
216#my $nodes = osmutil::get_nodes ($username, $password, "247989,264385,270534");
217#print STDERR "NODE: $nodes\n";
218
219exit 0;
220
221my $data = "<osm version='0.2'>
222<node lon='15.558601' tags='' lat='58.408306'/>
223</osm>";
224
225my $uid = curl::put_data ("newnode", $data, "$username", $password);
226
227##my $uid = 275900;
228
229my $resp = curl::get ("node/$uid", "$username", $password);
230
231print "RESP: $resp\n";
232
233$resp = curl::delete ("node/$uid", "$username", $password);
234
235print "RESP: $resp\n";
236
237my $resp = curl::get ("node/$uid", "$username", $password);
238
239print "RESP: $resp\n";
240
Note: See TracBrowser for help on using the repository browser.