Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mazur93/078cb7da9c8a55bca3f9e1187839811c to your computer and use it in GitHub Desktop.
Save Mazur93/078cb7da9c8a55bca3f9e1187839811c to your computer and use it in GitHub Desktop.
Here is a simple python 3 script that downloads all OSM data within a given bounding box via the overpass API
# author: Bartosz Mazurkiewicz
# Downloading OSM data via the overpass API with python3. Pay attention to not generate that much traffic.
# The servers are for everyone and the resources are limited. See the usage policy at http://wiki.openstreetmap.org/wiki/Overpass_API
import time
import os
import urllib.request
# Bounding box - example Florence, Italy
north = str(43.8)
south = str(43.75)
east = str(11.3)
west = str(11.2)
# bbox=west,south,east,north
url = 'http://www.overpass-api.de/api/map?bbox=' + west + ',' + south + ',' + east + ',' + north
# Download osm data and print download time
start = time.time()
urllib.request.urlretrieve(url, 'DataOSM.osm')
end = time.time()
print("Download OSM data took " + str(end-start) + " seconds")
print("Data size is about " + str(os.path.getsize(os.path.join(os.getcwd(), "DataOSM.osm"))/1000000) + " mb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment