source: subversion/applications/editors/osmpedit/test @ 34614

Last change on this file since 34614 was 1105, checked in by tpersson, 13 years ago

Fixed bug with non unique id

File size: 6.3 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 $tags = {};
59    my $uid = osmutil::create_node ($lat, $lon, $tags, $username, $password);
60    print STDERR "UID: $uid\n";
61    exit 0;
62}
63
64if (defined $opt_deletenode) {
65    my $resp = osmutil::delete_node ($opt_deletenode, $username, $password);
66    print STDERR "DELETE: $resp\n";
67    exit 0;
68}
69
70if (defined $opt_getnode) {
71    my $node = osmutil::get_node ($opt_getnode, $username, $password);
72    print "NODE: $node\n";
73    exit 0;
74}
75
76if (defined $opt_getnodehistory) {
77    my $node = osmutil::get_node_history ($opt_getnodehistory, $username, $password);
78    print "NODE: $node\n";
79    exit 0;
80}
81
82
83if (defined $opt_getseg) {
84    my $s = osmutil::get_segment ($opt_getseg, $username, $password);
85    print "SEGMENT: $s\n";
86    exit 0;
87}
88
89if (defined $opt_getseghistory) {
90    my $s = osmutil::get_segment_history ($opt_getseghistory, $username, $password);
91    print "SEGMENT: $s\n";
92    exit 0;
93}
94
95if (defined $opt_getsegways) {
96    my $s = osmutil::get_segment_ways ($opt_getsegways, $username, $password);
97    print "SEGMENT $opt_getsegways WAYS: $s\n";
98    exit 0;
99}
100
101if (defined $opt_getsegareas) {
102    my $s = osmutil::get_segment_areas ($opt_getsegareas, $username, $password);
103    print "SEGMENT $opt_getsegways AREAS: $s\n";
104    exit 0;
105}
106
107
108if (defined $opt_createseg) {
109    my $tags = {};
110    if (not defined $opt_from) {
111        print STDERR "--from must be defined\n";
112        exit 1;
113    }
114    if (not defined $opt_to) {
115        print STDERR "--to must be defined\n";
116        exit 1;
117    }
118    my $resp = osmutil::create_segment ($opt_from, $opt_to, $tags, $username,
119                                        $password);
120    print "Segment created: $resp\n";
121    exit 0;
122}
123
124if (defined $opt_deleteseg) {
125    my $uid = $opt_deleteseg;
126    my $resp = osmutil::delete_segment ($uid, $username, $password);
127    if (not $resp) {
128        print "DELETE FAILED: $uid\n";
129    } else {
130        print "Segment $uid deleted\n";;
131    }
132    exit 0;
133}
134
135
136
137if (defined $opt_getway) {
138    my $s = osmutil::get_way ($opt_getway, $username, $password);
139    print "WAY: $s\n";
140    exit 0;
141}
142
143if (defined $opt_getwayhistory) {
144    my $s = osmutil::get_way_history ($opt_getwayhistory, $username, $password);
145    print "WAY: $s\n";
146    exit 0;
147}
148
149if (defined $opt_createway) {
150    my $tags = {};
151    my $resp = osmutil::create_way ($tags, $username, $password);
152    print "Way created: $resp\n";
153    exit 0;
154}
155
156if (defined $opt_deleteway) {
157    my $uid = $opt_deleteway;
158    my $resp = osmutil::delete_way ($uid, $username, $password);
159    if (not $resp) {
160        print "DELETE FAILED: $uid\n";
161    } else {
162        print "Way $uid deleted\n";;
163    }
164    exit 0;
165}
166
167if (defined $opt_nodetagupdate) {
168
169    #
170    # Does not work, old method
171    #
172
173    my $uid = osmutil::create_node ($lat, $lon, "", $username, $password);
174    print STDERR "UID: $uid\n";
175
176    if ($uid < 0) {
177        print STDERR "Failure creating node\n";
178        exit 0;
179    }
180   
181    my $node = osmutil::get_node ($uid, $username, $password);
182    print STDERR "NODE: $node\n";
183   
184    if (not osmutil::update_node ($uid, $lat, $lon, "name=Tommy1;",
185                                  $username, $password)) {
186        print STDERR "Update failed\n";
187    }
188   
189    $node = osmutil::get_node ($uid, $username, $password);
190    print STDERR "UPDATED NODE 1: $node\n";
191   
192    if (not osmutil::update_node ($uid, $lat, $lon, "name=Tommy2;",
193                                  $username, $password)) {
194        print STDERR "Update failed\n";
195    }
196   
197    my $node = osmutil::get_node ($uid, $username, $password);
198    print STDERR "UPDATED NODE 2: $node\n";
199   
200#    if (not osmutil::update_node_tags ($uid, "name=Tommy3;",
201#                                      $username, $password)) {
202#       print STDERR "Update tags failed\n";
203#    }
204   
205#    my $node = osmutil::get_node ($uid, $username, $password);
206#    print STDERR "UPDATED NODE 3: $node\n";
207   
208   
209    my $resp = osmutil::delete_node ($uid, $username, $password);
210    if (not $resp) {
211        print "DELETE FAILED: $uid\n";
212    } else {
213        print "Node $uid deleted\n";;
214    }
215    exit 0;
216}
217
218
219#my $nodes = osmutil::get_nodes ($username, $password, "247989,264385,270534");
220#print STDERR "NODE: $nodes\n";
221
222exit 0;
223
224my $data = "<osm version='0.2'>
225<node lon='15.558601' tags='' lat='58.408306'/>
226</osm>";
227
228my $uid = curl::put_data ("newnode", $data, "$username", $password);
229
230##my $uid = 275900;
231
232my $resp = curl::get ("node/$uid", "$username", $password);
233
234print "RESP: $resp\n";
235
236$resp = curl::delete ("node/$uid", "$username", $password);
237
238print "RESP: $resp\n";
239
240my $resp = curl::get ("node/$uid", "$username", $password);
241
242print "RESP: $resp\n";
243
Note: See TracBrowser for help on using the repository browser.