Skip to content

Commit 3338aa9

Browse files
committed
update clip tool rules
1 parent 19d39b0 commit 3338aa9

File tree

3 files changed

+7
-58
lines changed

3 files changed

+7
-58
lines changed

docs/python/sdk-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ You will need your ACCESS_KEY_ID, SECRET_ACCESS_KEY, bucket and region name.
225225
To subscribe to scenes that match a filter, use the `subscription_request` module to build a request, and
226226
pass it to the `subscriptions.create_subscription()` method of the client.
227227

228-
By default, a request to create a subscription will not clip matching imagery which intersects the source geometry. To clip to the subscription source geometry, set `planet.subscription_request.build_request()` keyword argument `clip_to_source = True` as in the example below. To clip to a custom geometry, set `planet.subscription_request.build_request()` keyword argument `clip_to_source = False` (or omit it entirely to fall back on the default value), and instead configure the custom clip AOI with `planet.subscription_request.clip_tool()`.
228+
By default, a request to create a subscription will not clip matching imagery which intersects the source geometry. To clip to the subscription source geometry, set `planet.subscription_request.build_request()` keyword argument `clip_to_source = True` as in the example below. Custom clip AOIs are no longer supported in subscriptions.
229229

230230
Warning: the following code will create a subscription, consuming quota based on your plan.
231231

planet/subscription_request.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def build_request(name: str,
7272
collection_id: A Sentinel Hub collection ID.
7373
create_configuration: Automatically create a layer configuration for your collection.
7474
clip_to_source: Whether or not to clip to the source geometry (defaults to False). If
75-
True, a clip configuration that specifies the subscription source geometry as clip
76-
AOI will be added to the list of requested tools. If True and 'clip_tool()' is
77-
also specified, an exception will be raised. If False, no clip configuration
78-
will be added to the list of requested tools unless 'clip_tool()' is specified.
75+
True, a clip configuration will be added to the list of requested tools that
76+
automatically clips to the subscription source geometry. If True and a clip tool is
77+
also specified in the tools list, an exception will be raised. If False, no clip
78+
configuration will be added to the list of requested tools.
7979
8080
Returns:
8181
dict: a representation of a Subscriptions API request for
@@ -136,12 +136,7 @@ def build_request(name: str,
136136
"clip_to_source option conflicts with a configured clip tool."
137137
)
138138
else:
139-
tool_list.append({
140-
'type': 'clip',
141-
'parameters': {
142-
'aoi': source['parameters']['geometry']
143-
}
144-
})
139+
tool_list.append({'type': 'clip', 'parameters': {}})
145140

146141
details['tools'] = tool_list
147142

@@ -638,41 +633,6 @@ def band_math_tool(b1: str,
638633
return _tool('bandmath', parameters)
639634

640635

641-
def clip_tool(aoi: Mapping) -> dict:
642-
"""Specify a subscriptions API clip tool.
643-
644-
Imagery and udm files will be clipped to your area of interest. nodata
645-
pixels will be preserved. Xml file attributes “filename”, “numRows”,
646-
“numColumns” and “footprint” will be updated based on the clip results.
647-
648-
The clipped output files will have “_clip” appended to their file names. If
649-
the clip aoi is so large that full scenes may be delivered without any
650-
clipping, those files will not have “_clip” appended to their file name.
651-
652-
NOTE: To clip to the source geometry, set the 'clip_to_source' parameter
653-
of 'planet.subscription_request.build_request()' to True instead of using
654-
this tool.
655-
656-
Parameters:
657-
aoi: GeoJSON polygon or multipolygon defining the clip area, with up to
658-
500 vertices. The minimum geographic area of any polygon or
659-
internal ring is one square meter.
660-
661-
Raises:
662-
planet.exceptions.ClientError: If aoi is not a valid polygon or
663-
multipolygon.
664-
"""
665-
666-
valid_types = ['Polygon', 'MultiPolygon', 'ref']
667-
668-
geom = geojson.as_geom_or_ref(dict(aoi))
669-
if geom['type'].lower() not in [v.lower() for v in valid_types]:
670-
raise ClientError(
671-
f'Invalid geometry type: {geom["type"]} is not in {valid_types}.')
672-
673-
return _tool('clip', {'aoi': geom})
674-
675-
676636
def file_format_tool(file_format: str) -> dict:
677637
"""Specify a subscriptions API file format tool.
678638

tests/unit/test_subscription_request.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_build_request_clip_to_source_success(geom_geojson):
8787
clip_to_source=True,
8888
)
8989
assert req["tools"][1]["type"] == "clip"
90-
assert req["tools"][1]["parameters"]["aoi"] == geom_geojson
90+
assert req["tools"][1]["parameters"] == {}
9191

9292

9393
def test_build_request_clip_to_source_failure(geom_geojson):
@@ -499,17 +499,6 @@ def test_band_math_tool_invalid_pixel_type():
499499
pixel_type="invalid")
500500

501501

502-
def test_clip_tool_success(geom_geojson):
503-
res = subscription_request.clip_tool(geom_geojson)
504-
expected = {"type": "clip", "parameters": {"aoi": geom_geojson}}
505-
assert res == expected
506-
507-
508-
def test_clip_tool_invalid_type(point_geom_geojson):
509-
with pytest.raises(exceptions.ClientError):
510-
subscription_request.clip_tool(point_geom_geojson)
511-
512-
513502
def test_file_format_tool_success():
514503
res = subscription_request.file_format_tool('COG')
515504

0 commit comments

Comments
 (0)