Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created October 18, 2017 20:49
Show Gist options
  • Save TimSC/ccdae73d5d08f5dd181dee11281aa59c to your computer and use it in GitHub Desktop.
Save TimSC/ccdae73d5d08f5dd181dee11281aa59c to your computer and use it in GitHub Desktop.
Download a range of changesets from an OSM map server
import urllib2
import xml.etree.ElementTree as ET
import sys
import time
if __name__=="__main__":
top = ET.Element('osm')
i = 1000000001
running = True
outCount = 0
outFileCount = 0
while running:
url = "http://api.fosm.org/api/0.6/changeset/{}".format(i)
print i
try:
response = urllib2.urlopen(url)
except urllib2.HTTPError as err:
print err
#running = False
i += 1
time.sleep(0.1)
continue
xml = response.read()
root = ET.fromstring(xml)
for el in root:
top.append(el)
outCount += 1
if outCount >= 1000:
ET.ElementTree(top).write(
open("{:05d}.osm".format(outFileCount), "wt"), encoding="UTF-8")
top = ET.Element('osm')
outCount = 0
outFileCount += 1
i += 1
time.sleep(0.1)
if i > 1000079522:
running = False
ET.ElementTree(top).write(open("{:05d}.osm".format(outFileCount), "wt"), encoding="UTF-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment