Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Created February 4, 2017 13:08
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 Trass3r/10e8633ab35ddacd6580af6c8153d3c6 to your computer and use it in GitHub Desktop.
Save Trass3r/10e8633ab35ddacd6580af6c8153d3c6 to your computer and use it in GitHub Desktop.
download aerial imagery from Geoportal TH
import requests
from urllib.request import *
import sys
import os.path
def getDetails(type, id):
url = 'http://geoportal.geoportal-th.de/gaialight-th/_apps/dladownload/_ajax/details.php'
params = dict(
type = type,
id = id
)
resp = requests.get(url=url, params=params)
data = resp.json()
assert data['success']
return data['object']
def download(type, id, localfilepath):
if os.path.isfile(localfilepath):
sys.stdout.write('Skipping %s\n' % localfilepath)
return
sys.stdout.write('Downloading %s\n' % localfilepath)
url = 'http://geoportal.geoportal-th.de/gaialight-th/_apps/dladownload/download.php'
params = dict(
type = type,
id = id
)
urlretrieve(url + '?type=%s&id=%s' % (type, id), localfilepath, reporthook=dlProgress)
sys.stdout.write('\n')
def dlProgress(count, blockSize, totalSize):
percent = int(count * blockSize * 100 / totalSize)
sys.stdout.write("\rDownloading...%d%%" % percent)
sys.stdout.flush()
LLx = 622735.64705765
LLy = 5641515.8748382
URx = 624180.40247649
URy = 5642599.4414024
crs = 'EPSG%3A25832'
minDate = '1943-01-01T00%3A00%3A00.000Z'
maxDate = '1946-12-01T00%3A00%3A00.000Z'
url = 'http://geoportal.geoportal-th.de/gaialight-th/_apps/dladownload/_ajax/overview.php'
url += '?bbox%5B%5D={0}&bbox%5B%5D={1}&bbox%5B%5D={2}&bbox%5B%5D={3}&crs={4}&minDate={5}&maxDate={6}&type%5B%5D=lb&type%5B%5D=op'.format(LLx, LLy, URx, URy, crs, minDate, maxDate)
resp = requests.get(url=url)
data = resp.json()
assert data['success']
result = data["result"]
crs = result['crs']['name']
features = result['features']
for feature in features:
geometry = feature['geometry']
properties = feature['properties']
# details = getDetails(properties['type'], properties['gid'])
download(properties['type'], properties['gid'], r'%s_%s_pan.zip' % (properties['bildflugnr'], properties['bildnr']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment