Skip to content

Instantly share code, notes, and snippets.

@Hummer12007
Created October 21, 2018 09:44
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 Hummer12007/9e06e46394ccea3877a48df64156539b to your computer and use it in GitHub Desktop.
Save Hummer12007/9e06e46394ccea3877a48df64156539b to your computer and use it in GitHub Desktop.
from gbdxtools import CatalogImage, TmsImage, Interface
from gbdxtools.task import env
import json
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
import time
from sys import argv, exit
from os import makedirs
gbdx = Interface(username='hilobakho@gmail.com', password='Qwer1234')
MAPS_API_KEY='pk.eyJ1IjoiZGlnaXRhbGdsb2JlIiwiYSI6ImNqajRxNmFnNjFpYnozbHVvcmZtaHpkMmYifQ.eA28FwVViY_WHcKdztUP5A'
tms=TmsImage(access_token=MAPS_API_KEY, zoom=18)
if len(argv) != 6: exit(0)
_, name, lat1, lon1, lat2, lon2 = argv
makedirs(argv[1], exist_ok=True)
lat1 = float(lat1)
lon1 = float(lon1)
lat2 = float(lat2)
lon2 = float(lon2)
bbox = [lon1, lat1, lon2, lat2]
#bbox = env.inputs.get('bbox', '33.574676, 10.116096, 33.603586, 10.087682')
#bbox = list(map(float, bbox.split(',')))
search_area = "POLYGON(({} {},{} {}))".format(*bbox)
results = gbdx.catalog.search(searchAreaWkt=search_area,
startDate="2010-01-01T00:00:00.000Z",
endDate="2019-01-01T00:00:00.000Z",
types=["DigitalGlobeProduct"])
with open('{}/results.json'.format(name), 'w') as f:
json.dump(results, f)
def order(cid, bbox):
print('Ordering {}'.format(cid))
pre_order = gbdx.Task("Auto_Ordering")
pre_order.inputs.cat_id = cid
pre_order.impersonation_allowed = True
pre_order.persist = True
pre_order.timeout = 36000
workflow = gbdx.Workflow([pre_order])
workflow.execute()
while workflow.status['event'] != "succeeded":
if workflow.status['event'] == 'failed':
print('Order failed')
return None
else:
print(workflow.status)
time.sleep(2)
pass
return CatalogImage(cid, bbox=bbox)
i = 0
for res in results:
print(i, '/', len(results))
i += 1
cid = res['properties']['catalogID']
ts = res['properties']['timestamp']
print(ts, cid)
if not cid.startswith('1'): continue
if int(res['properties']['cloudCover']) > 20: continue
try:
img = CatalogImage(cid, bbox=bbox)
plt.imsave('{}/{}-{}.png'.format(name, ts, cid), img.rgb())
except Exception as e:
print(e)
#img = order(cid, bbox)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment