Last active
November 12, 2015 21:37
-
-
Save olafveerman/da64dd90a2b0c315f263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Diff two OSM changesets and output a list with | |
# node id's that are only in the original changeset | |
import re | |
def getIDs(f): | |
s = set() | |
for line in f: | |
match = re.search('node id="([0-9]+)"', line) | |
if match: | |
s.add(match.group(1)) | |
return s | |
# construct a set with reverted nodes | |
with open('reverted-nodes.xml', 'rb') as r: | |
revertedNodes = getIDs(r) | |
# construct a set with the original nodes | |
with open('original-nodes.xml', 'rb') as o: | |
originalNodes = getIDs(o) | |
# diff the two sets | |
nodesToRevert = originalNodes - revertedNodes | |
print '# nodes originally added: ' + str(len(originalNodes)) | |
print '# nodes already reverted: ' + str(len(revertedNodes)) | |
print '# nodes still to be reverted: ' + str(len(nodesToRevert)) | |
with open('changeset.xml', 'w') as f: | |
f.write('<osmChange version="0.6" generator="script">\n') | |
for node in nodesToRevert: | |
f.write('<delete>\n<node id="' + node + '" changeset="35271390" version="1" visible="false" />\n</delete>\n') | |
f.write('</osmChange>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment