Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download the Earth from World Imagery (Esri)
import subprocess
import pathlib
# Source
map_server = 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/'
# Output directory
outdir = 'images/'
pathlib.Path(outdir).mkdir(parents=True, exist_ok=True)
# Range of zoom levels to download
min_zoom_level = 2
max_zoom_level = 6 #max_zoom_level = 12 gives 2^11 (2048 x 2048 tiles)
# DEBUG:
zooms = list(range(min_zoom_level, max_zoom_level))
resolutions = list([ 2**j for j in zooms ])
print('zooms', zooms, 'resolutions', resolutions)
# Prepare file with list of downloads
urls_filename = 'urls.txt'
with open(urls_filename, 'w') as urls_file:
# Go over each zoom level
for zoom_level in zooms:
res = 2**zoom_level
zoom_dir = outdir + str(zoom_level)
pathlib.Path(zoom_dir).mkdir(parents=True, exist_ok=True)
url_requests = []
for i in range(res):
for j in range(res):
output_filename = '{}_{}_{}.jpg'.format(zoom_level,i,j)
url = map_server+str(zoom_level)+"/"+str(i)+"/"+str(j)
url_request = url + "\n\tdir=" + zoom_dir + "\n\tout=" + output_filename
url_requests.append(url_request)
# DEBUG:
#print('Requests', url_requests)
# Save download list
for item in url_requests:
urls_file.write("%s\n" % item)
# Download the files
subprocess.call(['aria2c', '-i ' + urls_filename, '-j 10'], shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment