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

index.delete requires unique ids and errors not thrown #76

Open
thehesiod opened this issue Sep 21, 2016 · 10 comments
Open

index.delete requires unique ids and errors not thrown #76

thehesiod opened this issue Sep 21, 2016 · 10 comments

Comments

@thehesiod
Copy link

thehesiod commented Sep 21, 2016

per http://toblerity.org/rtree/class.html#rtree.index.Index.delete it states for the id parameter to delete: long integer A long integer that is the identifier for this index entry. IDs need not be unique to be inserted into the index, and it is up to the user to ensure they are unique if this is a requirement.

However I tried this with with an Index which had a set of points which all had the same ids and it never removed it items. As soon as I gave each point a unique id the points got removed.

There are two bugs here:

  1. documentation should be updated or implementation fixed
  2. the python code should be checking error code returned by Index_DeleteData and throwing exception if the delete failed. Probably should go over the whole index.py file to make sure returned error codes are enforced.
@thehesiod thehesiod changed the title (documentation?) index.delete requires unique ids index.delete requires unique ids Sep 21, 2016
@thehesiod thehesiod changed the title index.delete requires unique ids index.delete requires unique ids and errors not thrown Sep 21, 2016
@sr-murthy
Copy link
Collaborator

@thehesiod I assume this remains an open issue - if so can I work on it?

@hobu
Copy link
Member

hobu commented Dec 11, 2019

This is still an open issue, but I think it is a documentation one. libspatialindex indexes by bounding boxes + id, and to delete a unique record, you need to provide both.

@sr-murthy
Copy link
Collaborator

Yes, this makes sense because insertion of entries requires a (not necessarily unique) ID and a bounding box. It does seem strange that insertion of duplicate entries (entries with identical IDs and bounding boxes) does not throw an error - should this in fact be addressed first before the delete issue?

In [1]: from rtree.index import Index

In [2]: idx = Index()

In [3]: idx.insert(1, (0.0, 0.0, 0.0, 0.0), obj=1)                                                                               

In [4]: idx.insert(1, (0.0, 0.0, 0.0, 0.0), obj=1)                                                                               

In [5]: idx.leaves()                                                                                                             
Out[5]: [(0, [1, 1], [0.0, 0.0, 0.0, 0.0])] 

Why is this allowed in the first place?

@hobu
Copy link
Member

hobu commented Dec 11, 2019

libspatialindex allows it. It is up to user applications to prevent it from happening.

@thehesiod
Copy link
Author

If it's a doc problem that is fine, let's get it fixed :)

@sr-murthy
Copy link
Collaborator

OK, I'm happy to work on it.

@sr-murthy
Copy link
Collaborator

I've created a PR here

#133

that clarifies the docstring for index.Index.delete. I hope it addresses the documentation side of this issue. Clearly, as the index allows insertion of multiple items/entries with identical IDs and coordinates, it is up to the user to enforce uniqueness at the application level.

@sr-murthy
Copy link
Collaborator

@hobu @thehesiod What should be done about the error/exception issue?

@thehesiod
Copy link
Author

That's a question for hobu

@hobu
Copy link
Member

hobu commented Dec 15, 2019

I think documentation is sufficient. I don't think Rtree should throw an exception in this instance. It is possible users have a reason to insert duplicates, and they should protect against that themselves if they need to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants