Skip to content

Commit 84944f6

Browse files
charceyCopilot
andauthored
Subscriptions: add support for subscription's catalog source's geometry_relation (#1203)
* add support for subscription catalog source geometry_relation * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * reformat help string --------- Co-authored-by: Copilot <[email protected]>
1 parent 193a79a commit 84944f6

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

planet/cli/subscriptions.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,18 @@ def request(name,
518518
@click.option('--time-range-type',
519519
type=click.Choice(["acquired", "published"]),
520520
help="Subscribe by acquisition time or time of publication.")
521+
@click.option(
522+
'--geometry-relation',
523+
type=click.Choice(["intersects", "contains", "within"]),
524+
help= # noqa: E251
525+
('\b\n'
526+
'The relationship between the subscription geometry and the item geometry.\n'
527+
'intersects (default): Returns items whose footprint geometry partially or \n'
528+
'fully overlaps with the subscription geometry.\n'
529+
'contains: Returns items where the footprint geometry fully encloses the \n'
530+
'subscription geometry.\n'
531+
'within: Returns items whose entire footprint geometry is fully contained \n'
532+
'within the subscription geometry.'))
521533
@pretty
522534
def request_catalog(item_types,
523535
asset_types,
@@ -528,6 +540,7 @@ def request_catalog(item_types,
528540
filter,
529541
publishing_stages,
530542
time_range_type,
543+
geometry_relation,
531544
pretty):
532545
"""Generate a subscriptions request catalog source description."""
533546

@@ -540,7 +553,8 @@ def request_catalog(item_types,
540553
rrule=rrule,
541554
filter=filter,
542555
publishing_stages=publishing_stages,
543-
time_range_type=time_range_type)
556+
time_range_type=time_range_type,
557+
geometry_relation=geometry_relation)
544558
echo_json(res, pretty)
545559

546560

planet/subscription_request.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def catalog_source(
169169
"standard",
170170
"finalized"]]] = None,
171171
time_range_type: Optional[Literal["acquired", "published"]] = None,
172+
geometry_relation: Optional[Literal["intersects", "contains",
173+
"within"]] = None,
172174
) -> dict:
173175
"""Construct a Catalog subscription source.
174176
@@ -195,6 +197,10 @@ def catalog_source(
195197
publishing_stages: A sequence of one or more of the values
196198
"preview", "standard", or "finalized".
197199
time_range_type: "acquired" (new in 2.1.0) or "published".
200+
geometry_relation: The relationship between the subscription geometry and the item geometry.
201+
'intersects' (default): Returns items whose footprint geometry partially or fully overlaps with the subscription geometry.
202+
'contains': Returns items where the footprint geometry fully encloses the AOI.
203+
'within': Returns items whose entire footprint geometry is fully contained within the AOI.
198204
199205
Returns:
200206
dict: a representation of a subscription source.
@@ -270,6 +276,9 @@ def catalog_source(
270276
if time_range_type:
271277
parameters['time_range_type'] = time_range_type
272278

279+
if geometry_relation:
280+
parameters['geometry_relation'] = geometry_relation
281+
273282
return {"parameters": parameters}
274283

275284

tests/integration/test_subscriptions_cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,27 @@ def test_catalog_source_time_range_type(mock_bundles,
487487
assert req['parameters']['time_range_type'] == time_range_type
488488

489489

490+
@pytest.mark.parametrize("geometry_relation",
491+
["intersects", "contains", "within"])
492+
def test_catalog_source_geometry_relation(mock_bundles,
493+
invoke,
494+
geom_geojson,
495+
geometry_relation):
496+
"""Catalog source geometry relation is configured."""
497+
result = invoke([
498+
'request-catalog',
499+
'--item-types=PSScene',
500+
'--asset-types=ortho_analytic_4b',
501+
f"--geometry={json.dumps(geom_geojson)}",
502+
'--start-time=2021-03-01T00:00:00',
503+
f'--geometry-relation={geometry_relation}',
504+
])
505+
506+
assert result.exit_code == 0 # success.
507+
req = json.loads(result.output)
508+
assert req['parameters']['geometry_relation'] == geometry_relation
509+
510+
490511
@pytest.mark.parametrize(
491512
"hosting_option, collection_id_option, configuration_option, expected_success",
492513
[

tests/unit/test_subscription_request.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,20 @@ def test_catalog_source_time_range_type_acquired(geom_geojson, mock_bundles):
617617
assert source["parameters"]["time_range_type"] == "acquired"
618618

619619

620+
@respx.mock
621+
def test_catalog_source_geometry_relation_contains(geom_geojson, mock_bundles):
622+
"""Configure 'contains' geometry relation for a catalog source."""
623+
source = subscription_request.catalog_source(
624+
item_types=["PSScene"],
625+
asset_types=["ortho_analytic_4b"],
626+
start_time=datetime(2021, 3, 1),
627+
geometry_relation="contains",
628+
geometry=geom_geojson,
629+
)
630+
631+
assert source["parameters"]["geometry_relation"] == "contains"
632+
633+
620634
def test_cloud_filter_tool_success():
621635
res = subscription_request.cloud_filter_tool(
622636
clear_percent=subscription_request.FilterValue(gte=90),

0 commit comments

Comments
 (0)