Skip to content

Commit

Permalink
feat: ✨ add buffer search option to within search
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Jan 4, 2022
1 parent f23d800 commit 1ad3655
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyle38/commands/within.py
Expand Up @@ -121,6 +121,19 @@ def cursor(self, value: int) -> Within:

return self

def buffer(self, value: int) -> Within:
"""Apply a buffer around area formats to increase the search area by x meters.
Args:
value (int): buffer size in meters
Returns:
Within
"""
self._options["buffer"] = value

return self

def limit(self, value: int) -> Within:
"""Limit the number of returned objects in a search.
Expand Down
34 changes: 34 additions & 0 deletions tests/test_command_within.py
Expand Up @@ -37,6 +37,8 @@
key,
"MATCH",
"*",
"BUFFER",
10,
"NOFIELDS",
"SPARSE",
1,
Expand Down Expand Up @@ -72,6 +74,7 @@ async def test_command_within_compile(tile38, format, precision, expected):
query = (
Within(tile38.client, key)
.match("*")
.buffer(10)
.nofields()
.sparse(1)
.cursor(0)
Expand Down Expand Up @@ -274,3 +277,34 @@ async def test_command_within_return_bounds(tile38):
"sw": {"lat": 52.25, "lon": 13.37},
},
}


@pytest.mark.asyncio
async def test_command_within_buffer_return_count(tile38):
response = await tile38.set(key, id).object(feature).exec()
assert response.ok

search_area = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[13.37009847164154, 52.2498254610514],
[13.370516896247862, 52.2498254610514],
[13.370516896247862, 52.25017851139772],
[13.37009847164154, 52.25017851139772],
[13.37009847164154, 52.2498254610514],
]
],
},
}

response = await tile38.within(key).object(search_area).asCount()
assert response.ok
assert response.count == 0

response = await tile38.within(key).buffer(10).object(search_area).asCount()
assert response.ok
assert response.count == 1

0 comments on commit 1ad3655

Please sign in to comment.