2014-12-27 22:26:00 +00:00
|
|
|
from rtree import index as rtindex
|
|
|
|
|
|
|
|
def pt2rect(pt):
|
|
|
|
return pt[0], pt[1], pt[0], pt[1]
|
|
|
|
|
|
|
|
pts = [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
|
|
|
|
|
2014-12-28 23:06:54 +00:00
|
|
|
p = rtindex.Property()
|
|
|
|
p.buffering_capacity = 1
|
|
|
|
p.dimension = 2
|
|
|
|
rt = rtindex.Index(properties=p)
|
|
|
|
#rt = rtindex.Index()
|
2014-12-27 22:26:00 +00:00
|
|
|
|
|
|
|
# If interleaved is True, the coordinates must be in
|
|
|
|
# the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax].
|
|
|
|
print rt.interleaved
|
|
|
|
|
|
|
|
[rt.add(0, pt2rect(pt)) for pt in pts]
|
|
|
|
print [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
|
|
|
|
|
|
|
|
for pt in pts:
|
|
|
|
rt.delete(0, pt2rect(pt))
|
|
|
|
print pt2rect(pt), [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
|
|
|
|
|