On Nov 24, 2009, at 11:23 AM, Andrew Byrd wrote:

> Hello,
> 
> I'm trying to delete items that have been added to an rtree Index. I  
> am finding that the items still exist after I thought they were  
> deleted. I am using spatialindex and rtree freshly checked out from  
> svn trunk, and compiled on OSX 10.5.6 with Python 2.6.
> 
> The following test demonstrates my situation:
> 
> $python
>>>> from rtree import Rtree
>>>> i = Rtree()
>>>> i.insert(1, (0,0,5,5))
>>>> i.insert(2, (1,1,6,6))
>>>> i.insert(3, (2,2,7,7))
>>>> i.intersection((3,3,4,4))
> [1L, 2L, 3L]
>>>> i.delete(2, (0,0,7,7))
>>>> i.intersection((3,3,4,4))
> [1L, 2L, 3L]
>>>> i.delete(2, (2,2,5,5))
>>>> i.intersection((3,3,4,4))
> [1L, 2L, 3L]
>>>> i.delete(2, (0.9,0.9,6.1,6.1))
>>>> i.intersection((3,3,4,4))
> [1L, 2L, 3L]
>>>> i.delete(2, (1,1,6,6))
>>>> i.intersection((3,3,4,4))
> [1L, 3L]
>>>> 
>>>> 
> 
> The item is not removed from the index when the window specified in  
> the delete method is larger that it, but only when the window exactly  
> matches its bounding box.
> 
> Is this the expected behavior, am I misunderstanding something?

Expected, yes.  "Uniqueness" in the sense of the rtree index is really the 
bounding box that is inserted into it plus the id, not merely the id.  I put 
uniqueness in scare quotes because I think you can actually have multiple id + 
bbox entries with the same value and delete will delete both of them (not 
verified though).  

I think you want something like a "range delete", which isn't implemented in 
either libspatialindex or its C API.  This would allow a user to do it in one 
shot quite quickly.  Right now, you can cobble this up by doing a 
.intersection(objects=True) and inspecting the resultant .id and .bbox elements 
of the results and *then* issuing the delete with that. 

Hope this helps,

Howard

 
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community

Reply via email to