# ./border_follower.pl 10359135 Germany 2 country state
use Geo::OSM::APIClientV5;
use Data::Dumper;
+$direction='left';
+if ($ARGV[0] eq '-r') {
+ $direction='right';
+ shift(@ARGV);
+}
$first_wayid=$ARGV[0];
$name=$ARGV[1];
$required_admin_level=$ARGV[2];
{
my ($message)=@_;
$node=$api->get_node($last);
- print "$message at $last $node->{lat} $node->{lon}\n";
+ print "$message at Node $last $node->{lat} $node->{lon}\n";
$latl=$node->{lat}-0.01;
$lath=$node->{lat}+0.01;
$lonl=$node->{lon}-0.01;
$lonh=$node->{lon}+0.01;
- system("wget -O error.osm http://www.openstreetmap.org/api/0.5/map?bbox=$lonl,$latl,$lonh,$lath ; java -jar ~/map/osm/josm/josm-latest.jar error.osm --selection=id:$last");
+ system("wget -O error.osm http://www.openstreetmap.org/api/0.5/map?bbox=$lonl,$latl,$lonh,$lath ; josm error.osm --selection=id:$last");
exit(1);
}
$reverse=0;
# print Dumper($tags);
while( my($k,$v) = splice @{$tags}, 0, 2 ) {
- if (($k eq "left:$type" || $k eq "left:$alt_type") && $v eq $name) {
+ if (($k eq "$direction:$type" || $k eq "$direction:$alt_type") && $v eq $name) {
$reverse=1;
}
}
$count=0;
foreach $way (@$ways) {
$newid=$way->{'id'};
- print "Way $newid\n";
+ $timestamp=$way->{'timestamp'};
+ if ($newid == $lastid) {
+ next;
+ }
+ $nodes=$way->nodes;
+ print "way $newid ($#$nodes nodes) $timestamp\n";
my $tags = $way->tags;
$match=0;
$boundary=0;
$admin_level=0;
while( my($k,$v) = splice @{$tags}, 0, 2 ) {
print "tag: $k=$v\n";
- if (($k eq "left:$type" || $k eq "right:$type") && $newid != $lastid) {
+ if (($k eq "left:$type" || $k eq "right:$type")) {
if ($v eq $name) {
$match=1;
} else {
$neighbors{$v}=$newid;
}
}
- if (($k eq "left:$alt_type" || $k eq "right:$alt_type") && $v eq $name && $newid != $lastid) {
+ if (($k eq "left:$alt_type" || $k eq "right:$alt_type") && $v eq $name) {
print "Warning: $k in $newid\n";
$match=1;
}
}
}
}
- print "match=$match\n";
if ($match) {
+ print "MATCH\n";
if ($boundary != 1 ) {
print "boundary $boundary wrong at $newid\n"
}
$count++;
}
}
- if ($count != 1) {
- error "Count: $count != 1"
- } else {
- $path="$path $wayid";
+ if ($count == 0) {
+ error "No connection"
+ } else {
+ if ($count > 1) {
+ error "Multiple connections ($count)"
+ } else {
+ $path="$path $wayid";
+ }
}
} while ($wayid != $first_wayid);
print "End reached\n";
--- /dev/null
+#! /usr/bin/perl
+use Geo::OSM::APIClientV5;
+use Data::Dumper;
+
+sub print_error
+{
+ print Dumper($api->{last_error});
+ print 'Error:' . $api->{last_error}->rc . "\n";
+}
+
+sub print_entitiy
+{
+ my ($res)=@_;
+
+ my ($xml);
+ $xml=$res->xml;
+ $xml=~s/>/>\n/g;
+ print $xml;
+}
+
+sub remove_member
+{
+ my ($res,$type,$id)=@_;
+
+ my (@members);
+ my $found=0;
+ foreach my $member (@{$res->members}) {
+ if ($member->member_type eq $type && $member->ref eq $id) {
+ $found++;
+ } else {
+ push(@members, $member);
+ }
+ }
+ if ($found) {
+ $res->set_members(\@members);
+ }
+ return $found;
+}
+
+sub cmd_delete
+{
+ my($type,$id)=@_;
+ my($res);
+ $res=$api->get($type,$id);
+ if (!$api->delete($res)) {
+ print_error();
+ return 1;
+ }
+ return 0;
+}
+
+sub cmd_get
+{
+ my($type,$id)=@_;
+
+ my($res,$xml);
+ $res=$api->get($type,$id);
+ print_entitiy($res);
+}
+
+sub cmd_relations
+{
+ my($type,$id)=@_;
+
+ my($res,$xml);
+ $res=$api->get($type,$id,"relations");
+ print_entitiy($res);
+}
+
+sub cmd_remove_member_all
+{
+ my($type,$id)=@_;
+
+ my($res);
+ $res=$api->get($type,$id,"relations");
+ if (!remove_member($res,$type,$id)) {
+ print "Error:Member not found\n";
+ return 1;
+ }
+ if (!$api->modify($res)) {
+ print_error();
+ return 1;
+ }
+ return 0;
+}
+
+sub cmd_reload
+{
+ my($type,$id)=@_;
+ $res=$api->get($type,$id);
+ if (!$api->modify($res)) {
+ print_error();
+ return 1;
+ }
+ return 0;
+}
+
+sub command
+{
+ my(@arg)=@_;
+
+ if ($arg[0] eq 'delete') {
+ cmd_delete($arg[1],$arg[2]);
+ }
+ if ($arg[0] eq 'get') {
+ cmd_get($arg[1],$arg[2]);
+ }
+ if ($arg[0] eq 'relations') {
+ cmd_relations($arg[1],$arg[2]);
+ }
+ if ($arg[0] eq 'remove-member-all') {
+ cmd_remove_member_all($arg[1],$arg[2]);
+ }
+ if ($arg[0] eq 'reload') {
+ cmd_reload($arg[1],$arg[2]);
+ }
+}
+
+while (substr($ARGV[0],0,2) eq '--') {
+ $expr=substr($ARGV[0],2);
+ ($key,$value)=split('=',$expr,2);
+ $attr{$key}=$value;
+ shift;
+}
+$api=new Geo::OSM::APIClient(api=>'http://www.openstreetmap.org/api/0.5',%attr);
+command(@ARGV);