Skip to content

Commit

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

return self

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

return self

def fence(self, flag: bool = True) -> Intersects:
"""Flag to indicate that the Intersects Query is used for a geo fence.
Expand Down
1 change: 1 addition & 0 deletions pyle38/models.py
Expand Up @@ -14,6 +14,7 @@ class Options(TypedDict, total=False):
distance: Optional[bool]
asc: Optional[bool]
desc: Optional[bool]
buffer: Optional[int]


class CircleQuery(BaseModel):
Expand Down
34 changes: 34 additions & 0 deletions tests/test_command_intersects.py
Expand Up @@ -37,6 +37,8 @@
key,
"MATCH",
"*",
"BUFFER",
10,
"NOFIELDS",
"SPARSE",
1,
Expand Down Expand Up @@ -73,6 +75,7 @@ async def test_command_intersects_compile(tile38, format, precision, expected):
query = (
Intersects(tile38.client, key)
.match("*")
.buffer(10)
.nofields()
.sparse(1)
.clip()
Expand Down Expand Up @@ -327,3 +330,34 @@ async def test_command_intersects_return_bounds(tile38):
"sw": {"lat": 52.25, "lon": 13.37},
},
}


@pytest.mark.asyncio
async def test_command_intersects_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.intersects(key).object(search_area).asCount()
assert response.ok
assert response.count == 0

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

0 comments on commit f23d800

Please sign in to comment.