Created
May 24, 2018 09:22
-
-
Save ialhashim/68a8ff2358ece7b4e3c9a78f1da941cf to your computer and use it in GitHub Desktop.
Download the Earth from World Imagery (Esri)
This file contains hidden or 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
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