Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created November 10, 2018 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimSC/0ec87d5ee40c16464e1a0bbde3fdb0a5 to your computer and use it in GitHub Desktop.
Save TimSC/0ec87d5ee40c16464e1a0bbde3fdb0a5 to your computer and use it in GitHub Desktop.
Find non existent referenced objects in osm osc change file
from pyo5m import OsmData
import requests
if __name__=="__main__":
#
osc = OsmData.OsmChange()
osc.LoadFromOscXml(open("bad_changeset.osc", "rb"))
refNodes, refWays, refRelations = set(), set(), set()
for n in osc.create.nodes:
pass
for w in osc.create.ways:
for cn in w[3]:
refWays.add(cn)
for r in osc.create.relations:
for objType, objId, objRole in r[3]:
if objType == "node":
refNodes.add(objId)
elif objType == "way":
refWays.add(objId)
elif objType == "relation":
refRelations.add(objId)
for n in osc.modify.nodes:
refNodes.add(n[0])
for w in osc.modify.ways:
refWays.add(w[0])
for cn in w[3]:
refNodes.add(cn)
for r in osc.modify.relations:
refRelations.add(r[0])
for objType, objId, objRole in r[3]:
if objType == "node":
refNodes.add(objId)
elif objType == "way":
refWays.add(objId)
elif objType == "relation":
refRelations.add(objId)
for n in osc.delete.nodes:
refNodes.add(n[0])
for w in osc.delete.ways:
refWays.add(w[0])
for cn in w[3]:
refNodes.add(cn)
for r in osc.delete.relations:
refRelations.add(r[0])
for objType, objId, objRole in r[3]:
if objType == "node":
refNodes.add(objId)
elif objType == "way":
refWays.add(objId)
elif objType == "relation":
refRelations.add(objId)
print (len(refNodes))
print (len(refWays))
print (len(refRelations))
#for n in refNodes:
# if n < 0:
# continue
# req = requests.get('http://api.fosm.org/api/0.6/node/{}'.format(n))
# print ("n", n, req.status_code)
for w in refWays:
if w < 0:
continue
req = requests.get('http://api.fosm.org/api/0.6/way/{}'.format(w))
print ("w", w, req.status_code)
for r in refRelations:
if r < 0:
continue
req = requests.get('http://api.fosm.org/api/0.6/relation/{}'.format(r))
print ("r", r, req.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment