Skip to content

Commit 788a90e

Browse files
authored
feat: allow "Feature" dictionaries for intersects (#696)
1 parent e6f530a commit 788a90e

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Support for "Feature" type `intersects` dictionaries [#696](https://github.com/stac-utils/pystac-client/pull/696)
13+
1014
## [v0.8.1] - 2024-05-23
1115

1216
### Fixed

pystac_client/item_search.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,10 @@ class ItemSearch:
179179
bbox: A list, tuple, or iterator representing a bounding box of 2D
180180
or 3D coordinates. Results will be filtered
181181
to only those intersecting the bounding box.
182-
intersects: A string or dictionary representing a GeoJSON geometry, or
183-
an object that implements a
184-
``__geo_interface__`` property, as supported by several libraries
185-
including Shapely, ArcPy, PySAL, and
186-
geojson. Results filtered to only those intersecting the geometry.
182+
intersects: A string or dictionary representing a GeoJSON geometry or feature,
183+
or an object that implements a ``__geo_interface__`` property, as supported
184+
by several libraries including Shapely, ArcPy, PySAL, and geojson. Results
185+
filtered to only those intersecting the geometry.
187186
datetime: Either a single datetime or datetime range used to filter results.
188187
You may express a single datetime using a :class:`datetime.datetime`
189188
instance, a `RFC 3339-compliant <https://tools.ietf.org/html/rfc3339>`__
@@ -646,7 +645,10 @@ def _format_intersects(value: Optional[IntersectsLike]) -> Optional[Intersects]:
646645
if value is None:
647646
return None
648647
if isinstance(value, dict):
649-
return deepcopy(value)
648+
if value.get("type") == "Feature":
649+
return deepcopy(value.get("geometry"))
650+
else:
651+
return deepcopy(value)
650652
if isinstance(value, str):
651653
return dict(json.loads(value))
652654
if hasattr(value, "__geo_interface__"):

tests/test_item_search.py

+14
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,17 @@ def test_fields() -> None:
850850
assert "geometry" not in item
851851
assert "assets" not in item
852852
assert "links" not in item
853+
854+
855+
def test_feature() -> None:
856+
search = ItemSearch(
857+
url="https://earth-search.aws.element84.com/v1/search",
858+
intersects={
859+
"type": "Feature",
860+
"geometry": {"type": "Point", "coordinates": [-105.1019, 40.1672]},
861+
},
862+
)
863+
assert search.get_parameters()["intersects"] == {
864+
"type": "Point",
865+
"coordinates": [-105.1019, 40.1672],
866+
}

0 commit comments

Comments
 (0)