I was inspired to do this because a few TIGER uploads have had "issues"
when someone deleted nodes in the middle of an upload.  So far, I've
fixed those up by hand, but they *SUCK* to do that way.

Anyway, here's an update to the perl APIClientV5 which allows bringing
objects "back from the dead".  I've attached another script modified
from bulk_upload.pl to call into the new APIClientV5 function:
resurrect().

It'll also check ways that you want resurrected to ensure that all of
the nodes are in place and exist before performing its actions.

Thoughts?

-- Dave
Index: APIClientV5.pm
===================================================================
--- APIClientV5.pm	(revision 6103)
+++ APIClientV5.pm	(working copy)
@@ -153,8 +153,11 @@
   my $self = shift;
   my $type = shift;
   my $id = shift;
+  my $extra = shift;
   
-  my $req = new HTTP::Request GET => $self->{url}."/$type/$id";
+  $extra = "/".$extra if (defined $extra);
+
+  my $req = new HTTP::Request GET => $self->{url}."/$type/$id$extra";
   
   my $res = $self->_request($req);
 
@@ -168,14 +171,58 @@
   $self->{buffer} = [EMAIL PROTECTED];
   $self->{reader}->parse($res->content);
   undef $self->{buffer};
-  if( scalar(@res) != 1 )
+  if ($extra =~ /history/) {
+    return @res;
+  }
+  if(scalar(@res) != 1 )
   {
     die "Unexpected response for get_$type [".$res->content()."]\n";
   }
-  
+
   return $res[0];
 }
 
+sub resurrect($$)
+{
+  my $self = shift;
+  my $type = shift;
+  my $id = shift;
+
+  my $ret = $self->get($type, $id);
+  if (defined $ret || !defined $self->{last_error} || ($self->{last_error}->code != 410)) {
+    return $ret;
+  }
+  
+  my @ents = $self->get($type, $id, 'history');
+  # we want the last _visible_ one
+  my $ent = $ents[-2];
+  if ($ent->type eq 'way') {
+  	printf("resurrecting way, checking all member nodes...\n");
+	foreach my $node_id (@{$ent->nodes()}) {
+		printf("checking node: $node_id...");
+		my $node_ent = $self->get('node', $node_id);
+		if (defined $node_ent) {
+			printf("good\n");
+			next;
+		}
+		printf("attempting to resurrect node: $node_id...");
+		$node_ent = $self->resurrect('node', $node_id);
+		if (!defined $node_ent) {
+			die "failed";
+		}
+		printf("success!\n");
+	}
+  	printf("all way nodes are OK, ");
+  }
+  printf("attempting to resurrect %s...", $ent->type);
+  $ret = $self->modify($ent);
+  if ($ret == $ent->id) {
+	printf("ok\n");
+	return $ret;
+  }
+  die sprintf("unable to resurrect $type $id: %s\n", $self->last_error_message);
+}
+
 sub get_node($)
 {
   my $self = shift;
Index: OsmReaderV5.pm
===================================================================
--- OsmReaderV5.pm	(revision 6103)
+++ OsmReaderV5.pm	(working copy)
@@ -119,7 +119,6 @@
 # Function is called whenever an XML tag is started
 sub DoStart
 {
-#print @_,"\n";   
   my ($self, $Expat, $Name, %Attr) = @_;
 
   if( $self->{state} == STATE_INIT )

Attachment: resurrect.pl
Description: Perl program

_______________________________________________
dev mailing list
[email protected]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev

Reply via email to