Skip to content

Commit

Permalink
Merge pull request #160 from stac-utils/get-intersection
Browse files Browse the repository at this point in the history
Enable GET /search intersection
  • Loading branch information
jonhealy1 authored Nov 7, 2023
2 parents 23dca8a + 5652fe8 commit 5d71684
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Collection-level Assets to the CollectionSerializer [#148](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/148)

### Added

- Examples folder with example docker setup for running sfes from pip [#147](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/147)
- Added support for GET /search intersection queries [#158](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/158)

### Changed

- Updated core stac-fastapi libraries to 2.4.8 from 2.4.3 [#151](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/151)
- Use aliases on Elasticsearch indices, add number suffix in index name. [#152](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/152)

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime as datetime_type
from datetime import timezone
from typing import Any, Dict, List, Optional, Set, Type, Union
from urllib.parse import urljoin
from urllib.parse import unquote_plus, urljoin

import attr
import stac_pydantic
Expand Down Expand Up @@ -325,7 +325,7 @@ async def get_search(
base_args["datetime"] = datetime

if intersects:
base_args["intersects"] = intersects
base_args["intersects"] = json.loads(unquote_plus(intersects))

if sortby:
# https://github.com/radiantearth/stac-spec/tree/master/api-spec/extensions/sort#http-get-or-post-form
Expand Down
26 changes: 25 additions & 1 deletion stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import uuid
from datetime import datetime, timedelta

import pytest

from ..conftest import create_collection, create_item

ROUTES = {
Expand Down Expand Up @@ -233,7 +235,29 @@ async def test_search_invalid_date(app_client, ctx):
assert resp.status_code == 400


async def test_search_point_intersects(app_client, ctx):
@pytest.mark.asyncio
async def test_search_point_intersects_get(app_client, ctx):
resp = await app_client.get(
'/search?intersects={"type":"Point","coordinates":[150.04,-33.14]}'
)

assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
async def test_search_polygon_intersects_get(app_client, ctx):
resp = await app_client.get(
'/search?intersects={"type":"Polygon","coordinates":[[[149.04, -34.14],[149.04, -32.14],[151.04, -32.14],[151.04, -34.14],[149.04, -34.14]]]}'
)

assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 1


async def test_search_point_intersects_post(app_client, ctx):
point = [150.04, -33.14]
intersects = {"type": "Point", "coordinates": point}

Expand Down

0 comments on commit 5d71684

Please sign in to comment.