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

Update bulk interface to match changes in libspatialindex. #343

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions rtree/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,13 @@ def intersection_v(self, mins, maxs):
ids = ids.resize(2 * len(ids), refcheck=False)

def nearest_v(
self, mins, maxs, num_results=1, strict=False, return_max_dists=False
self,
mins,
maxs,
num_results=1,
max_dists=None,
strict=False,
return_max_dists=False,
):
import numpy as np

Expand All @@ -1114,10 +1120,18 @@ def nearest_v(

ids = np.empty(n * num_results, dtype=np.int64)
counts = np.empty(n, dtype=np.uint64)
dists = np.empty(n) if return_max_dists else None
nr = ctypes.c_int64(0)
offn, offi = 0, 0

if max_dists is not None:
assert len(max_dists) == n

dists = max_dists.astype(np.float64).copy()
elif return_max_dists:
dists = np.zeros(n)
else:
dists = None

while True:
core.rt.Index_NearestNeighbors_id_v(
self.handle,
Expand All @@ -1131,7 +1145,7 @@ def nearest_v(
maxs[offn:].ctypes.data,
ids[offi:].ctypes.data,
counts[offn:].ctypes.data,
dists[offn:].ctypes.data if return_max_dists else None,
dists[offn:].ctypes.data if dists is not None else None,
ctypes.byref(nr),
)

Expand Down
Loading