Skip to content

Stream / generate nearest neighbors #366

@dfuhry

Description

@dfuhry

I am storing polygons / linestrings and I would like to stream (generate) nearest neighbors. This requires first iterating through nearest bounding boxes in order, with true-distance comparisons between the geometries they contain, and at some point cutting off that search.

Right now with the nearest() method I can get a fixed number of nearest neighbor bounding boxes to my query bounding box via the method's second parameter:

https://rtree.readthedocs.io/en/latest/tutorial.html#nearest-neighbors

But I cannot stream bounding boxes out with a generator. If I pass the length of the dataset as the second parameter then I can iterate through that list, but this is very slow for large datasets because it returns all boxes in the dataset sorted by distance, whereas in practice I likely need only the first few. (However the exact number I need depends on exact distance checks between the contained geometries, so I don't exactly know it beforehand.)

I'm not sure whether the inability to generate / yield a list of nearest-neighbor bounding boxes is a libspatialindex limitation, or only one of this library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions