Created
March 3, 2020 21:53
-
-
Save richpsharp/289c35e12726048b840323e077a78f8f to your computer and use it in GitHub Desktop.
Planet Bounding Box quad query demo for Sam
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 argparse | |
import requests | |
def demo(mosaic_id, planet_api_key): | |
"""Demo of searching multiple bounding boxes. | |
Parameters: | |
mosaic_id (str): planet mosaic id. | |
planet_api_key (str): Planet API key. | |
Returns: | |
None. | |
""" | |
session = requests.Session() | |
session.auth = (planet_api_key, '') | |
bb_list = [ | |
[-54.1520512104035, -15.4639278500847, -54.1514396667481, -15.4628317609468], | |
[-54.1617983579636, -15.4649057932912, -54.1611653566361, -15.4639306481247], | |
[-52.3038576215937, -15.0286879308609, -52.3029561614206, -15.0261818330127], | |
[-58.2029619812966, -15.6270690313958, -58.2020124793053, -15.6265808320473], | |
[-52.3027625901159, -15.6830265092333, -52.3019230586942, -15.6828379972032]] | |
for lx, ly, ux, uy in bb_list: | |
bb_query_url = ( | |
'https://api.planet.com/basemaps/v1/mosaics/' | |
'%s/quads?bbox=%f,%f,%f,%f' % (mosaic_id, lx, ly, ux, uy)) | |
mosaics_json = session.get( | |
bb_query_url, timeout=5.0) | |
for item in (mosaics_json.json())['items']: | |
print(item['id']) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
description='Planet bounding box query demo for Sam.') | |
parser.add_argument('planet_api_key') | |
# That hardcoded id is 2019 q2 mosaic | |
parser.add_argument( | |
'--mosaic_id', type=str, default='4ce5863a-fb3f-4cad-a899-b8c053af1858') | |
args = parser.parse_args() | |
demo(args.mosaic_id, args.planet_api_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment