test_rt.py 598 B

123456789101112131415161718192021222324
  1. from rtree import index as rtindex
  2. def pt2rect(pt):
  3. return pt[0], pt[1], pt[0], pt[1]
  4. pts = [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
  5. #p = rtindex.Property()
  6. #p.buffering_capacity = 1
  7. #rt = rtindex.Index(properties=p)
  8. rt = rtindex.Index()
  9. # If interleaved is True, the coordinates must be in
  10. # the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax].
  11. print rt.interleaved
  12. [rt.add(0, pt2rect(pt)) for pt in pts]
  13. print [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
  14. for pt in pts:
  15. rt.delete(0, pt2rect(pt))
  16. print pt2rect(pt), [r.bbox for r in list(rt.nearest((0, 0), 10, True))]