source: subversion/applications/editors/osmpedit/osmpcommand @ 2475

Last change on this file since 2475 was 1134, checked in by tpersson, 13 years ago

More support for ways added

  • Property svn:executable set to *
File size: 4.4 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 $opt_to $opt_lat $opt_lon $opt_passwd $opt_user);
25
26use Getopt::Mixed;
27Getopt::Mixed::getOptions("getseg=s getseghistory=s createseg deletesegment=s
28                           getsegways=s getsegareas=s
29                           getnode=s getnodehistory=s createnode deletenode=s
30                           getway=s getwayhistory=s createway deleteway=s
31                           from=s to=s lat=s lon=s
32                           passwd=s user=s");
33
34
35my $username = $opt_user;
36my $password = $opt_passwd;
37
38if (defined $opt_createnode) {
39    my $tags = {};
40    if (defined $opt_lat and defined $opt_lon) {
41        my $id = osmutil::create_node ($opt_lat, $opt_lon,
42                                       $tags, $username, $password);
43        print STDERR "Created node with id: $id\n";
44    } else {
45        print STDERR "--lon and --lat must be specified\n";
46    }
47    exit 0;
48}
49
50if (defined $opt_deletenode) {
51    my $resp = osmutil::delete_node ($opt_deletenode, $username, $password);
52    if ($resp) {
53        print STDERR "Node $opt_deletenode deleted\n";
54    } else {
55        print STDERR "DELETE OF $opt_deletenode FAILED\n";
56    }
57    exit 0;
58}
59
60if (defined $opt_getnode) {
61    my $node = osmutil::get_node ($opt_getnode, $username, $password);
62    print "NODE: $node\n";
63    exit 0;
64}
65
66if (defined $opt_getnodehistory) {
67    my $node = osmutil::get_node_history ($opt_getnodehistory, $username, $password);
68    print "NODE: $node\n";
69    exit 0;
70}
71
72
73if (defined $opt_getseg) {
74    my $s = osmutil::get_segment ($opt_getseg, $username, $password);
75    print "SEGMENT: $s\n";
76    exit 0;
77}
78
79if (defined $opt_getseghistory) {
80    my $s = osmutil::get_segment_history ($opt_getseghistory, $username, $password);
81    print "SEGMENT: $s\n";
82    exit 0;
83}
84
85if (defined $opt_getsegways) {
86    my $s = osmutil::get_segment_ways ($opt_getsegways, $username, $password);
87    print "SEGMENT $opt_getsegways WAYS: $s\n";
88    exit 0;
89}
90
91if (defined $opt_getsegareas) {
92    my $s = osmutil::get_segment_areas ($opt_getsegareas, $username, $password);
93    print "SEGMENT $opt_getsegways AREAS: $s\n";
94    exit 0;
95}
96
97
98if (defined $opt_createseg) {
99    my $tags = {};
100    if (not defined $opt_from) {
101        print STDERR "--from must be defined\n";
102        exit 1;
103    }
104    if (not defined $opt_to) {
105        print STDERR "--to must be defined\n";
106        exit 1;
107    }
108    my $resp = osmutil::create_segment ($opt_from, $opt_to, $tags, $username,
109                                        $password);
110    print "Segment created: $resp\n";
111    exit 0;
112}
113
114if (defined $opt_deleteseg) {
115    my $uid = $opt_deleteseg;
116    my $resp = osmutil::delete_segment ($uid, $username, $password);
117    if (not $resp) {
118        print "DELETE FAILED: $uid\n";
119    } else {
120        print "Segment $uid deleted\n";;
121    }
122    exit 0;
123}
124
125
126
127if (defined $opt_getway) {
128    my $s = osmutil::get_way ($opt_getway, $username, $password);
129    print "WAY: $s\n";
130    exit 0;
131}
132
133if (defined $opt_getwayhistory) {
134    my $s = osmutil::get_way_history ($opt_getwayhistory, $username, $password);
135    print "WAY: $s\n";
136    exit 0;
137}
138
139if (defined $opt_createway) {
140    my $segs = ();
141    my $tags = {};
142##    push @{$segs}, "57853";
143    $tags->{"name"} = "test way";
144    my $resp = osmutil::create_way ($segs, $tags, $username, $password);
145    print "Way created: $resp\n";
146    exit 0;
147}
148
149if (defined $opt_deleteway) {
150    my $uid = $opt_deleteway;
151    my $resp = osmutil::delete_way ($uid, $username, $password);
152    if (not $resp) {
153        print "DELETE FAILED: $uid\n";
154    } else {
155        print "Way $uid deleted\n";;
156    }
157    exit 0;
158}
159
Note: See TracBrowser for help on using the repository browser.