Skip to content

Commit

Permalink
Update bulk interface to match changes in libspatialindex.
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddieWitherden committed Dec 19, 2024
1 parent 2ca2ea1 commit 612738a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions rtree/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,8 @@ 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
):
def nearest_v(self, mins, maxs, num_results=1, max_dists=None,
strict=False, return_max_dists=False):
import numpy as np

assert mins.shape == maxs.shape
Expand All @@ -1114,10 +1113,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,8 +1138,8 @@ 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,
ctypes.byref(nr),
dists[offn:].ctypes.data if dists is not None else None,
ctypes.byref(nr)
)

# If we got the expected nuber of results then return
Expand Down

0 comments on commit 612738a

Please sign in to comment.