Skip to content

bulk create order example now demonstrates use of a dynamic list #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 52 additions & 45 deletions examples/orders_create_and_download_multiple_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,51 @@

DOWNLOAD_DIR = os.getenv('TEST_DOWNLOAD_DIR', '.')

# The Orders API will be asked to mask, or clip, results to
# this area of interest.
iowa_aoi = {
"type":
"Polygon",
"coordinates": [[[-91.198465, 42.893071], [-91.121931, 42.893071],
[-91.121931, 42.946205], [-91.198465, 42.946205],
[-91.198465, 42.893071]]]
}

# In practice, you will use a Data API search to find items, but
# for this example take them as given.
iowa_items = ['20200925_161029_69_2223', '20200925_161027_48_2223']

iowa_order = planet.order_request.build_request(
name='iowa_order',
products=[
planet.order_request.product(item_ids=iowa_items,
product_bundle='analytic_udm2',
item_type='PSScene')
],
tools=[planet.order_request.clip_tool(aoi=iowa_aoi)])

oregon_aoi = {
"type":
"Polygon",
"coordinates": [[[-117.558734, 45.229745], [-117.452447, 45.229745],
[-117.452447, 45.301865], [-117.558734, 45.301865],
[-117.558734, 45.229745]]]
}

oregon_items = ['20200909_182525_1014', '20200909_182524_1014']

oregon_order = planet.order_request.build_request(
name='oregon_order',
products=[
planet.order_request.product(item_ids=oregon_items,
product_bundle='analytic_udm2',
item_type='PSScene')
],
tools=[planet.order_request.clip_tool(aoi=oregon_aoi)])

def create_requests():
# The Orders API will be asked to mask, or clip, results to
# this area of interest.
iowa_aoi = {
"type":
"Polygon",
"coordinates": [[[-91.198465, 42.893071], [-91.121931, 42.893071],
[-91.121931, 42.946205], [-91.198465, 42.946205],
[-91.198465, 42.893071]]]
}

# In practice, you will use a Data API search to find items, but
# for this example take them as given.
iowa_items = ['20200925_161029_69_2223', '20200925_161027_48_2223']

iowa_order = planet.order_request.build_request(
name='iowa_order',
products=[
planet.order_request.product(item_ids=iowa_items,
product_bundle='analytic_udm2',
item_type='PSScene')
],
tools=[planet.order_request.clip_tool(aoi=iowa_aoi)])

oregon_aoi = {
"type":
"Polygon",
"coordinates": [[[-117.558734, 45.229745], [-117.452447, 45.229745],
[-117.452447, 45.301865], [-117.558734, 45.301865],
[-117.558734, 45.229745]]]
}

oregon_items = ['20200909_182525_1014', '20200909_182524_1014']

oregon_order = planet.order_request.build_request(
name='oregon_order',
products=[
planet.order_request.product(item_ids=oregon_items,
product_bundle='analytic_udm2',
item_type='PSScene')
],
tools=[planet.order_request.clip_tool(aoi=oregon_aoi)])

return [iowa_order, oregon_order]


async def create_and_download(client, order_detail, directory):
Expand All @@ -84,10 +88,13 @@ async def create_and_download(client, order_detail, directory):
async def main():
async with planet.Session() as sess:
client = sess.client('orders')
await asyncio.gather(
create_and_download(client, iowa_order, DOWNLOAD_DIR),
create_and_download(client, oregon_order, DOWNLOAD_DIR),
)

requests = create_requests()

await asyncio.gather(*[
create_and_download(client, request, DOWNLOAD_DIR)
for request in requests
])


if __name__ == '__main__':
Expand Down