Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (51 sloc) 2.39 KB
#!/usr/bin/perl -w
use strict;
use warnings;
use XML::SemanticDiff;
use XML::LibXML;
# OSMXML_mark_modified_JOSM-style marks locally modified objects with action="modify"
#
# JOSM marks locally modified objects with action="modify"
# Doing the same when editing with other tools that are not action="modify"-aware is tedious
# so OSMXML_mark_modified_JOSM-style does it for you,
# freeing you to edit OSM XML in your favourite text editor for example
#
# Usage :
# 1 - get a file containing Openstreetmap XML data from the public repository ($originalOSMfile)
# 2 - produce a copy of this file ($JOSMfile)
# 3 - edit $JOSMfile to your heart's content
# 4 - run this script to add action="modify" to the XML element of each Openstreetmap object that
# differs between $originalOSMfile and $JOSMfile
# 5 - review $JOSMfile in JOSM
# 6 - upload your contribution to Openstreetmap
#
# BLOODY SERIOUSLY REVIEW YOUR CONTRIBUTION IN JOSM BEFORE UPLOADING
# OR THE OPENSTREETMAP USERS WILL COME TO EAT YOU ALIVE IN YOUR SLEEP !
#
# (this applies especially if you performed automated processing on the file)
#
# Command line:
# OSMXML_mark_modified_JOSM-style originalOSMfile.xml locally_modified_originalOSMfile.xml
my ($originalOSMfile, $JOSMfile) = @ARGV;
usage() unless defined $originalOSMfile and defined $JOSMfile;
my $parser = XML::LibXML->new();
my $JOSM = $parser->parse_file($JOSMfile);
my $diff = XML::SemanticDiff->new();
foreach my $change ($diff->compare($originalOSMfile, $JOSMfile)) {
# "node" in get_node() and nodeName() must be understood in its XML DOM context, not its Openstreetmap meaning
# In DOM, first node is 1 not 0
# We want the first one - actually in this case it is the only one, but find returns a node list
my $JOSMchange = $JOSM->find("$change->{context}")->get_node(1);
my $nodeName = $JOSMchange->nodeName;
# $JOSMchange may be an attribute - we want the parent Openstreetmap object
until(($JOSMchange->nodeName eq "node") or ($JOSMchange->nodeName eq "way") or ($JOSMchange->nodeName eq "relation"))
{ $JOSMchange = $JOSMchange->parentNode; }
$JOSMchange->setAttribute("action", "modify");
# Printing to stdout superfluous but gives you a glimpse of modified elements
print "$JOSMchange->nodeName()\n";
}
my $savestate = $JOSM->toFile($JOSMfile, 2);
sub usage {
die "usage: $0 originalOSMfile.xml locally_modified_originalOSMfile.xml \n";
}
exit;