Skip to content

Commit

Permalink
feat: allow "Feature" dictionaries for intersects (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored May 30, 2024
1 parent e6f530a commit 788a90e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Support for "Feature" type `intersects` dictionaries [#696](https://github.com/stac-utils/pystac-client/pull/696)

## [v0.8.1] - 2024-05-23

### Fixed
Expand Down
14 changes: 8 additions & 6 deletions pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ class ItemSearch:
bbox: A list, tuple, or iterator representing a bounding box of 2D
or 3D coordinates. Results will be filtered
to only those intersecting the bounding box.
intersects: A string or dictionary representing a GeoJSON geometry, or
an object that implements a
``__geo_interface__`` property, as supported by several libraries
including Shapely, ArcPy, PySAL, and
geojson. Results filtered to only those intersecting the geometry.
intersects: A string or dictionary representing a GeoJSON geometry or feature,
or an object that implements a ``__geo_interface__`` property, as supported
by several libraries including Shapely, ArcPy, PySAL, and geojson. Results
filtered to only those intersecting the geometry.
datetime: Either a single datetime or datetime range used to filter results.
You may express a single datetime using a :class:`datetime.datetime`
instance, a `RFC 3339-compliant <https://tools.ietf.org/html/rfc3339>`__
Expand Down Expand Up @@ -646,7 +645,10 @@ def _format_intersects(value: Optional[IntersectsLike]) -> Optional[Intersects]:
if value is None:
return None
if isinstance(value, dict):
return deepcopy(value)
if value.get("type") == "Feature":
return deepcopy(value.get("geometry"))
else:
return deepcopy(value)
if isinstance(value, str):
return dict(json.loads(value))
if hasattr(value, "__geo_interface__"):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,17 @@ def test_fields() -> None:
assert "geometry" not in item
assert "assets" not in item
assert "links" not in item


def test_feature() -> None:
search = ItemSearch(
url="https://earth-search.aws.element84.com/v1/search",
intersects={
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-105.1019, 40.1672]},
},
)
assert search.get_parameters()["intersects"] == {
"type": "Point",
"coordinates": [-105.1019, 40.1672],
}

0 comments on commit 788a90e

Please sign in to comment.