test_rt.py 618 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. p.dimension = 2
  8. rt = rtindex.Index(properties=p)
  9. #rt = rtindex.Index()
  10. # If interleaved is True, the coordinates must be in
  11. # the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax].
  12. print((rt.interleaved))
  13. [rt.add(0, pt2rect(pt)) for pt in pts]
  14. print([r.bbox for r in list(rt.nearest((0, 0), 10, True))])
  15. for pt in pts:
  16. rt.delete(0, pt2rect(pt))
  17. print((pt2rect(pt), [r.bbox for r in list(rt.nearest((0, 0), 10, True))]))