-
Notifications
You must be signed in to change notification settings - Fork 13
/
quickdelways.pl
135 lines (119 loc) · 3.09 KB
/
quickdelways.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl
# quickdelways.pl
# ---------------
#
# Deletes a number of ways quickly, if the majority of them are still
# at v1. Cannot delete ways that are part of a relation. Does not delete
# ways of ways.
#
# Part of the "osmtools" suite of programs
# Originally written by Frederik Ramm <[email protected]>; public domain
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use Changeset;
use OsmApi;
if (scalar(@ARGV) != 1)
{
print <<EOF;
usage: $0 {<changeset>|<comment>}
where
comment is the comment for the changeset to be created;
if a changeset ID is given, re-use that changeset.
way ids are read from stdin.
EOF
exit;
}
my $full_cs=1;
my ($comment) = @ARGV;
my $ways=[];
while(<STDIN>)
{
chomp;
push(@$ways,$_);
}
my $current_cs;
if ($comment =~ /^[0-9]+$/)
{
$current_cs = $comment,
}
else
{
$current_cs = Changeset::create($comment);
}
die unless defined($current_cs);
my %wayver;
foreach my $n(@$ways)
{
$wayver{$n}=1;
}
if ($full_cs)
{
while(1)
{
my $c="<osmChange version=\"0.6\">\n<delete if-unused=\"1\">\n";
foreach my $n(keys %wayver)
{
$c .= "<way id=\"$n\" changeset=\"$current_cs\" version=\"" . $wayver{$n} . "\" />\n";
}
$c .= "</delete>\n</osmChange>\n";
OsmApi::set_timeout(7200);
my $resp = OsmApi::post("changeset/$current_cs/upload", $c);
if (!$resp->is_success)
{
my $c = $resp->content;
if ($c =~ /Version mismatch: Provided 1, server had: (\d+) of Way (\d+)/)
{
$wayver{$2}=$1;
print STDERR "adjusted way $2 version to $1\n";
next;
}
else
{
print STDERR "cannot upload changeset: ".$resp->status_line."\n";
print STDERR $resp->content."\n";
last;
}
}
else
{
print STDERR $resp->content."\n";
last;
}
}
}
else
{
foreach my $n(@$ways)
{
my $resp = OsmApi::delete("way/$n", "<osm version='0.6'>\n<way id='$n' version='1' changeset='$current_cs' /></osm>");
if ($resp->is_success)
{
printf(STDERR "deleted way $n\n");
next;
}
my $c = $resp->content;
if ($c =~ /already been deleted/)
{
printf(STDERR "already gone way $n\n");
next;
}
if ($c =~ /Version mismatch: Provided 1, server had: (\d+)/)
{
my $v=$1;
$resp = OsmApi::delete("way/$n", "<osm version='0.6'>\n<way id='$n' lat='0' lon='0' version='$v' changeset='$current_cs' /></osm>");
if ($resp->is_success)
{
printf(STDERR "deleted way $n ($v)\n");
next;
}
printf(STDERR "way $n ($v) cannot be deleted: %s\n", $resp->content);
}
else
{
printf(STDERR "way $n cannot be deleted: %s\n", $resp->content);
}
}
Changeset::close($current_cs) unless ($current_cs eq $comment);
}