Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "Feature" dictionaries for intersects #696

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
}
Loading