Skip to content

Commit 4482789

Browse files
committed
support data api clear coverage
- async client - cli
1 parent 4374ec8 commit 4482789

File tree

2 files changed

+120
-16
lines changed

2 files changed

+120
-16
lines changed

planet/cli/data.py

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -638,22 +638,67 @@ async def asset_wait(ctx, item_type, item_id, asset_type, delay, max_attempts):
638638
click.echo(status)
639639

640640

641-
# @data.command()
642-
# @click.pass_context
643-
# @translate_exceptions
644-
# @coro
645-
# @click.argument("item_type")
646-
# @click.argument("item_id")
647-
# @click.argument("asset_type_id")
648-
# @pretty
649-
# async def asset_get(ctx, item_type, item_id, asset_type_id, pretty):
650-
# """Get an item asset."""
651-
# async with data_client(ctx) as cl:
652-
# asset = await cl.get_asset(item_type, item_id, asset_type_id)
653-
# echo_json(asset, pretty)
654-
655-
# TODO: search_run()".
656-
# TODO: item_get()".
641+
@data.command() # type: ignore
642+
@click.pass_context
643+
@translate_exceptions
644+
@coro
645+
@click.argument("item_type")
646+
@click.argument("item_id")
647+
@click.argument("asset_type_id")
648+
async def asset_get(ctx, item_type, item_id, asset_type_id):
649+
"""Get an item asset."""
650+
async with data_client(ctx) as cl:
651+
asset = await cl.get_asset(item_type, item_id, asset_type_id)
652+
echo_json(asset, pretty)
653+
654+
655+
@data.command() # type: ignore
656+
@click.pass_context
657+
@translate_exceptions
658+
@coro
659+
@click.argument("item_type", type=str, callback=check_item_type)
660+
@click.argument("item_id")
661+
async def asset_list(ctx, item_type, item_id):
662+
"""List item assets."""
663+
async with data_client(ctx) as cl:
664+
item_assets = await cl.list_item_assets(item_type, item_id)
665+
echo_json(item_assets, pretty)
666+
667+
668+
@data.command() # type: ignore
669+
@click.pass_context
670+
@translate_exceptions
671+
@coro
672+
@click.argument("item_type", type=str, callback=check_item_type)
673+
@click.argument("item_id")
674+
async def item_get(ctx, item_type, item_id):
675+
"""Get an item."""
676+
async with data_client(ctx) as cl:
677+
item = await cl.get_item(item_type, item_id)
678+
echo_json(item, pretty)
679+
680+
681+
@data.command() # type: ignore
682+
@click.pass_context
683+
@translate_exceptions
684+
@coro
685+
@click.argument("item_type", type=str, callback=check_item_type)
686+
@click.argument("item_id")
687+
@click.option("--geom",
688+
type=types.Geometry(),
689+
callback=check_geom,
690+
required=True)
691+
@click.option('--mode', type=str, required=False)
692+
@click.option('--band', type=str, required=False)
693+
async def item_coverage(ctx, item_type, item_id, geom, mode, band):
694+
"""Get item clear coverage."""
695+
async with data_client(ctx) as cl:
696+
item_assets = await cl.get_item_coverage(item_type,
697+
item_id,
698+
geom,
699+
mode,
700+
band)
701+
echo_json(item_assets, pretty)
657702

658703

659704
@data.command() # type: ignore

planet/clients/data.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,65 @@ async def get_stats(self,
434434
json=request)
435435
return response.json()
436436

437+
async def get_item(self, item_type_id: str, item_id: str) -> dict:
438+
"""Get an item.
439+
440+
Retrives item details using the provided item_type_id and item_id
441+
442+
Parameters:
443+
item_type_id: Item type identifier.
444+
item_id: Item identifier.
445+
446+
Returns:
447+
Description of an item.
448+
449+
Raises:
450+
planet.exceptions.APIError: On API error.
451+
"""
452+
url = self._item_url(item_type_id, item_id)
453+
454+
response = await self._session.request(method="GET", url=url)
455+
return response.json()
456+
457+
async def get_item_coverage(
458+
self,
459+
item_type_id: str,
460+
item_id: str,
461+
geometry: GeojsonLike,
462+
mode: Optional[str] = None,
463+
band: Optional[str] = None,
464+
) -> dict:
465+
"""Estimate the clear coverage over an item within a custom AOI
466+
467+
Parameters:
468+
item_type_id: Item type identifier.
469+
item_id: Item identifier.
470+
geometry: A feature reference or a GeoJSON
471+
mode: Method used for coverage calculation
472+
band: Specific band to extract from UDM2
473+
474+
Returns:
475+
Description of the clear coverage for the provided AOI within the scene.
476+
477+
Raises:
478+
planet.exceptions.APIError: On API error.
479+
"""
480+
url = f"{self._item_url(item_type_id, item_id)}/coverage"
481+
482+
params = {}
483+
if mode is not None:
484+
params["mode"] = mode
485+
if band is not None:
486+
params["band"] = band
487+
488+
request_json = {'geometry': as_geom_or_ref(geometry)}
489+
490+
response = await self._session.request(method="POST",
491+
url=url,
492+
json=request_json,
493+
params=params)
494+
return response.json()
495+
437496
async def list_item_assets(self, item_type_id: str, item_id: str) -> dict:
438497
"""List all assets available for an item.
439498

0 commit comments

Comments
 (0)