update,
This commit is contained in:
31
vinniesniper-54816/task1/_lab/rtree/main.py
Normal file
31
vinniesniper-54816/task1/_lab/rtree/main.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from rtree import index
|
||||
from pprint import pprint
|
||||
import os, sys
|
||||
import rtree
|
||||
|
||||
|
||||
# Create a new index
|
||||
idx = rtree.index.Index()
|
||||
|
||||
# Insert a rectangle (minx, miny, maxx, maxy) with a unique identifier
|
||||
idx.insert(0, (0, 0, 0, 0))
|
||||
idx.insert(1, (30, 30, 30, 30))
|
||||
idx.insert(2, (40, 40, 40, 40))
|
||||
|
||||
# Query all rectangles that intersect with the given rectangle
|
||||
result = idx.intersection((2, 2, 8, 8))
|
||||
# for id in result:
|
||||
# print(id) # prints: 0
|
||||
|
||||
# Query all rectangles that are completely contained within the given rectangle
|
||||
# result = idx.intersection((1, 1, 9, 9), objects=True)
|
||||
# for id, bounds in result:
|
||||
# print(id, bounds) # prints: (0, (0, 0, 10, 10))
|
||||
|
||||
# # Query all rectangles that contain the given point
|
||||
result = idx.nearest((40, 35), 1)
|
||||
for id in result:
|
||||
print(id) # prints: (0, (0, 0, 10, 10))
|
||||
|
||||
# # Delete a rectangle by its identifier
|
||||
# idx.delete(0, (0, 0, 10, 10))
|
5
vinniesniper-54816/task1/_lab/rtree/setup.sh
Executable file
5
vinniesniper-54816/task1/_lab/rtree/setup.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
pip install rtree
|
Reference in New Issue
Block a user