Skip to content

Commit

Permalink
exclusive instead of exclude_geom
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Gillies committed Jul 12, 2021
1 parent 454a01c commit 39e7217
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions shapely/strtree.py
Expand Up @@ -251,7 +251,7 @@ def query(self, geom: BaseGeometry) -> Sequence[BaseGeometry]:
return self.query_geoms(geom)

def nearest_item(
self, geom: BaseGeometry, exclude_geom: bool = False
self, geom: BaseGeometry, exclusive: bool = False
) -> Union[Any, None]:
"""Query the tree for the node nearest to geom and get the item
stored in the node.
Expand All @@ -262,7 +262,7 @@ def nearest_item(
----------
geom : geometry object
The query geometry.
exclude_geom : bool, optional
exclusive : bool, optional
Whether to exclude the item corresponding to the given geom
from results or not. Default: False.
Expand Down Expand Up @@ -299,7 +299,7 @@ def callback(item1, item2, distance, userdata):
idx = ctypes.cast(item1, ctypes.py_object).value
geom2 = ctypes.cast(item2, ctypes.py_object).value
dist = ctypes.cast(distance, ctypes.POINTER(ctypes.c_double))
if callback_userdata["exclude_geom"] and self._rev[idx].equals(geom2):
if callback_userdata["exclusive"] and self._rev[idx].equals(geom2):
dist[0] = sys.float_info.max
else:
lgeos.GEOSDistance(self._rev[idx]._geom, geom2._geom, dist)
Expand All @@ -313,13 +313,13 @@ def callback(item1, item2, distance, userdata):
ctypes.py_object(geom),
envelope._geom,
lgeos.GEOSDistanceCallback(callback),
ctypes.py_object({"exclude_geom": exclude_geom}),
ctypes.py_object({"exclusive": exclusive}),
)
result = ctypes.cast(item, ctypes.py_object).value
return result

def nearest_geom(
self, geom: BaseGeometry, exclude_geom: bool = False
self, geom: BaseGeometry, exclusive: bool = False
) -> Union[BaseGeometry, None]:
"""Query the tree for the node nearest to geom and get the
geometry corresponding to the item stored in the node.
Expand All @@ -328,7 +328,7 @@ def nearest_geom(
----------
geom : geometry object
The query geometry.
exclude_geom : bool, optional
exclusive : bool, optional
Whether to exclude the given geom from results or not.
Default: False.
Expand All @@ -340,14 +340,14 @@ def nearest_geom(
version 2.0.
"""
item = self.nearest_item(geom, exclude_geom=exclude_geom)
item = self.nearest_item(geom, exclusive=exclusive)
if item is None:
return None
else:
return self._rev[item]

def nearest(
self, geom: BaseGeometry, exclude_geom: bool = False
self, geom: BaseGeometry, exclusive: bool = False
) -> Union[BaseGeometry, None]:
"""Query the tree for the node nearest to geom and get the
geometry corresponding to the item stored in the node.
Expand All @@ -359,7 +359,7 @@ def nearest(
----------
geom : geometry object
The query geometry.
exclude_geom : bool, optional
exclusive : bool, optional
Whether to exclude the given geom from results or not.
Default: False.
Expand All @@ -371,4 +371,4 @@ def nearest(
version 2.0.
"""
return self.nearest_geom(geom, exclude_geom=exclude_geom)
return self.nearest_geom(geom, exclusive=exclusive)
4 changes: 2 additions & 2 deletions tests/test_strtree.py
Expand Up @@ -192,7 +192,7 @@ def test_nearest_items(geoms, items):
)
@pytest.mark.parametrize("items", [list(range(1, 4)), list("abc")])
@pytest.mark.parametrize("query_geom", [Point(0, 0.5)])
def test_nearest_item_excluding(geoms, items, query_geom):
def test_nearest_item_exclusive(geoms, items, query_geom):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
assert tree.nearest_item(query_geom, exclude_geom=True) != items[0]
assert tree.nearest_item(query_geom, exclusive=True) != items[0]

0 comments on commit 39e7217

Please sign in to comment.