Python implementation of Priority R-Tree
Project description
python_prtree
"python_prtree" is a python implementation of Priority R-Tree (see reference below). Supported futures are as follows:
- Construct Priority R-Tree(PRTree) from rectangles; an array of (xmin, xmax, ymin, ymax)
- query and batch query with a rectangle(s)
- insert and erase(delete) (but not optimized yet)
This package is mainly for nearly static situations, which mean few insert/delete events happen (e.g., map-matching).
Usage
import numpy as np
from python_prtree import PRTree
idxes = np.array([1, 2]) # must be unique because it uses idx as key for hash map
rects = np.array([[0.0, 1.0, 0.0, 0.5],
[1.0, 1.2, 2.5, 3.0]]) # (xmin, xmax, ymin, ymax)
prtree = PRTree(idxes, rects) # initial construction
q = np.array([[0.5, 0.6, 0.2, 0.3],
[0.8, 1.5, 0.5, 3.5]])
result = prtree.batch_query(q)
print(result)
# [[1], [1, 2]]
New features(python-prtree>=0.3.0
)
You can save and load a binary file as follows:
# save
prtree.save('tree.bin')
# load with binary file
prtree = PRTree('tree.bin')
# or defered load
prtree = PRTree()
prtree.load('tree.bin')
Note
The 1d-array batch query will be implicitly treated as a batch with size = 1.
If you want 1d result, please use query
method.
result = prtree.query(q[0])
print(result)
# [1]
result = prtree.batch_query(q[0])
print(result)
# [[1]]
You can also erase(delete) by index and insert a new one.
prtree.erase(1) # delete the rectangle with idx=1 from the PRTree
prtree.insert(3, np.array([0.3, 0.5, 0.1, 0.2])) # add a new rectangle to the PRTree
Installation
To install python_prtree with pip command
pip install python-prtree
Or, you can clone and install just like
git clone --recursive https://github.com/atksh/python_prtree
cd python_prtree
python setup.py install
This installation needs cmake.
Performance
Construction
Query and batch query
Delete and insert
Requirement
- numpy
NOTE
- C++ implements this PRTree with Pybind11 and much faster than the numba implementation of PRTree.
- If you can use C++, you should use boost::geometry (I did not know it and sadly made this package).
- Please note that insert / erase operations are not optimized compared to ordinary r-tree. Plus, this implementation does not exactly follow that of the paper due to my technical skills.
Reference
The Priority R-Tree: A Practically Efficient and Worst-Case Optimal R-Tree Lars Arge, Mark de Berg, Herman Haverkort, and Ke Yi Proceedings of the 2004 ACM SIGMOD International Conference on Management of Data (SIGMOD '04), Paris, France, June 2004, 347-358. Journal version in ACM Transactions on Algorithms. author's page
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for python_prtree-0.3.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5425973fa3b04b7308199d580535bf4d66a8f3d74aae5b17364c950de8ddec24 |
|
MD5 | baec9e5e8841cfc75123338b939ee043 |
|
BLAKE2b-256 | 77f2eb172d389c7d44375ac2334f7b4353ef452801a46311a0cf6a2aec536027 |
Hashes for python_prtree-0.3.3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f314ab69f8f776910f289d3a2bfbe2b3eee420c2365c04703252ad3e01e7c061 |
|
MD5 | 01bc3a590c3fdcb2c8b4830a33a863c9 |
|
BLAKE2b-256 | 82f9618118eb874c418f3ba66083abf47e9f4c3fdb60c18d70947300a104bea2 |
Hashes for python_prtree-0.3.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f6045888b6939dc1c1bd1a7a850653261461bf68cfb9384d46ed28fde3837b |
|
MD5 | 9799d2f97cccff9cedcfb54aa31c5cac |
|
BLAKE2b-256 | 94b4047117e3902739c29117177ea6d455cdeba35276d227bfed65f9d74906d4 |
Hashes for python_prtree-0.3.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6c5e94c1471a4660b458f2d1fe0528dfecbe70450f70af12b3acf330a8c35fa |
|
MD5 | 5afd3d974c23c788e3ea14e41edf0d25 |
|
BLAKE2b-256 | e98ca419400fd733952e17ad34efbfaed838d32b61f07b7b914ce6456eae3ce9 |
Hashes for python_prtree-0.3.3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eadeb7343cea0ee9ae9018001382282615c433ce688cc9332a1fe02e1e9e5ec |
|
MD5 | cf0ed6e6cdfddcede5c940a0dce60868 |
|
BLAKE2b-256 | 59d4bf53144bfac5b75931fd4eb3ad4113d4111ee88323f4dcfb2107b262d61e |
Hashes for python_prtree-0.3.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5074e1a03688d12a51c98ac09f36bc1abf9c97eda2b403f2613dca7e7461aa74 |
|
MD5 | 0dc3cd355369860af0268ec48db27422 |
|
BLAKE2b-256 | 928ebfbdce2ff93dff25ea0edd21b368b35c9b6e548ac67eadec2cd5aa4fc04e |
Hashes for python_prtree-0.3.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e062c4a2099e8f7329f82f440421d257b59a7e9c3d3c8cdf77d99a6a8691d1 |
|
MD5 | c87019e4b65e6ef7608a480991e55f17 |
|
BLAKE2b-256 | f434b68897d11c6952d0d83978e3a646d330470124fb7ecb7ab40b3febd4b1e7 |
Hashes for python_prtree-0.3.3-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e22d566d8d756174407e2241ccfa85379f1cc8fc560ceaa1691b32ffc0691f8 |
|
MD5 | b18fa422aa88d557609646b4c7fe0115 |
|
BLAKE2b-256 | 5af1fccbd127b88884a968fbec3a46ae8c66727100386b44dcb89ea99dc4b974 |
Hashes for python_prtree-0.3.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e41783b21b049bbec7c7a2d2aeebc59fbcd03dc13d3f02f35cecca7bbd0fa3e |
|
MD5 | c2cca2bf9af6fe218cd61710f8a3da0b |
|
BLAKE2b-256 | aa0af0274d906c4ddc0e1853dee8f1bba7ff9b47331745b5e197347ec8121b7e |
Hashes for python_prtree-0.3.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 342cf76a077377ac69290e32d31810e300280a3e2260769c8b36368a079406e6 |
|
MD5 | 5c649c3fd4747660cf1e15b8420f25c1 |
|
BLAKE2b-256 | ec5369c233ecbe0fab0d44ea5f32f39e8e058d56655244f5e9755daa41f3b08b |
Hashes for python_prtree-0.3.3-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b76699823bd59511a570adc02e48399d7bb210ea21587a2627ce03f8f086c7 |
|
MD5 | c115aca0c94108e861847fbe747d9310 |
|
BLAKE2b-256 | 8bd9eb99e7a396f4077f5c4fc9620c31939623ac0e23c8d01f7f9b6fa7abbc9e |
Hashes for python_prtree-0.3.3-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bddab3fd6b1ec07dd64ea29085c481e62cba0c0300ee33d301f1701121b8494b |
|
MD5 | 0a75ce43f5ec6315ba58b9ce31f92500 |
|
BLAKE2b-256 | 530b29f1066f357fd6c26597e532820d582892f28a7d104e6675ef34be29a03e |