Skip to main content

Python implementation of Priority R-Tree

Reason this release was yanked:

delete arm wheel

Project description

python_prtree

python_prtree is a python/c++ implementation of the Priority R-Tree (see references below), an alternative to R-Tree. The supported futures are as follows:

  • Construct a Priority R-Tree (PRTree) from an array of rectangles.
    • PRTree2D, PRTree3D and PRTree4D (2D, 3D and 4D respectively)
  • insert and erase
    • The insert method can be passed pickable Python objects instead of int64 indexes.
  • query and batch_query
    • batch_query is parallelized by std::thread and is much faster than the query method.
    • The query method has an optional keyword argument return_obj; if return_obj=True, a Python object is returned.
  • rebuild
    • It improves performance when many insert/delete operations are called since the last rebuild.
    • Note that if the size changes more than 1.5 times, the insert/erase method also performs rebuild.

This package is mainly for mostly static situations where insertion and deletion events rarely occur.

Installation

You can install python_prtree with the pip command:

pip install python-prtree

If the pip installation does not work, please git clone clone and install as follows:

pip install -U cmake pybind11
git clone --recursive https://github.com/atksh/python_prtree
cd python_prtree
python setup.py install

Examples

import numpy as np
from python_prtree import PRTree2D

idxes = np.array([1, 2])

# rects is a list of (xmin, ymin, xmax, ymax)
rects = np.array([[0.0, 0.0, 1.0, 0.5],
                  [1.0, 1.5, 1.2, 3.0]])

prtree = PRTree2D(idxes, rects)


# batch query
q = np.array([[0.5, 0.2, 0.6, 0.3],
              [0.8, 0.5, 1.5, 3.5]])
result = prtree.batch_query(q)
print(result)
# [[1], [1, 2]]

# You can insert an additional rectangle by insert method,
prtree.insert(3, np.array([1.0, 1.0, 2.0, 2.0]))
q = np.array([[0.5, 0.2, 0.6, 0.3],
              [0.8, 0.5, 1.5, 3.5]])
result = prtree.batch_query(q)
print(result)
# [[1], [1, 2, 3]]

# Plus, you can erase by an index.
prtree.erase(2)
result = prtree.batch_query(q)
print(result)
# [[1], [1, 3]]

# Non-batch query is also supported.
print(prtree.query(0.5, 0.5))
# [1]
print(prtree.query((0.5, 0.5)))
# [1]
import numpy as np
from python_prtree import PRTree2D

objs = [{"name": "foo"}, (1, 2, 3)]  # must NOT be unique but pickable
rects = np.array([[0.0, 0.0, 1.0, 0.5],
                  [1.0, 1.5, 1.2, 3.0]])

prtree = PRTree2D()
for obj, rect in zip(objs, rects):
    prtree.insert(bb=rect, obj=obj)

# returns indexes genereted by incremental rule.
result = prtree.query((0, 0, 1, 1))
print(result)
# [1]

# returns objects when you specify the keyword argment return_obj=True
result = prtree.query((0, 0, 1, 1), return_obj=True)
print(result)
# [{'name': 'foo'}]

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.1, 0.5, 0.2]))  # add a new rectangle to the PRTree

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 that cross-version compatibility is NOT guaranteed, so please reconstruct your tree when you update this package.

Performance

Construction

2d

2d_fig1

3d

3d_fig1

Query and batch query

2d

2d_fig2

3d

3d_fig2

Delete and insert

2d

2d_fig3

3d

3d_fig3

New Features and Changes

python-prtree>=0.5.8

  • The insert method has been improved to select the node with the smallest mbb expansion.
  • The erase method now also executes rebuild when the size changes by a factor of 1.5 or more.

python-prtree>=0.5.7

  • You can use PRTree4D.

python-prtree>=0.5.3

  • Add compression for pickled objects.

python-prtree>=0.5.2

You can use pickable Python objects instead of int64 indexes for insert and query methods:

python-prtree>=0.5.0

  • Changed the input order from (xmin, xmax, ymin, ymax, ...) to (xmin, ymin, xmax, ymax, ...).
  • Added rebuild method to build the PRTree from scratch using the already given data.
  • Fixed a bug that prevented insertion into an empty PRTree.

python-prtree>=0.4.0

  • You can use PRTree3D:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_prtree-0.5.12.tar.gz (2.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_prtree-0.5.12-cp310-cp310-win_amd64.whl (142.1 kB view details)

Uploaded CPython 3.10Windows x86-64

python_prtree-0.5.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (189.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

python_prtree-0.5.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (175.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

python_prtree-0.5.12-cp310-cp310-macosx_12_0_arm64.whl (166.2 kB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

python_prtree-0.5.12-cp310-cp310-macosx_10_14_x86_64.whl (167.7 kB view details)

Uploaded CPython 3.10macOS 10.14+ x86-64

python_prtree-0.5.12-cp39-cp39-win_amd64.whl (139.1 kB view details)

Uploaded CPython 3.9Windows x86-64

python_prtree-0.5.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (189.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

python_prtree-0.5.12-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (175.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

python_prtree-0.5.12-cp39-cp39-macosx_12_0_arm64.whl (166.3 kB view details)

Uploaded CPython 3.9macOS 12.0+ ARM64

python_prtree-0.5.12-cp39-cp39-macosx_10_14_x86_64.whl (167.9 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

python_prtree-0.5.12-cp38-cp38-win_amd64.whl (142.8 kB view details)

Uploaded CPython 3.8Windows x86-64

python_prtree-0.5.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (189.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

python_prtree-0.5.12-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (175.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

python_prtree-0.5.12-cp38-cp38-macosx_12_0_arm64.whl (166.2 kB view details)

Uploaded CPython 3.8macOS 12.0+ ARM64

python_prtree-0.5.12-cp38-cp38-macosx_10_14_x86_64.whl (167.7 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

python_prtree-0.5.12-cp37-cp37m-win_amd64.whl (141.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (192.9 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (179.0 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

python_prtree-0.5.12-cp37-cp37m-macosx_10_14_x86_64.whl (166.4 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

python_prtree-0.5.12-cp36-cp36m-win_amd64.whl (141.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (192.8 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (179.0 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ ARM64

python_prtree-0.5.12-cp36-cp36m-macosx_10_14_x86_64.whl (166.3 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

Details for the file python_prtree-0.5.12.tar.gz.

File metadata

  • Download URL: python_prtree-0.5.12.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for python_prtree-0.5.12.tar.gz
Algorithm Hash digest
SHA256 8aeba694c76b524636a4d3031457316ef4621289002e355c99a12191ae21aeb5
MD5 6ba7e0d7c63db232be77f29c4a72c9be
BLAKE2b-256 465ff489eda9013703700772a37ffc4f00b99f3a3c381a9258030d982f57bcfc

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 18f9aedce77c1c15326128567b47f1cacc6ca016fa7a17b22f31c2bccebcda36
MD5 f3323f15a791457b795397160cc6377c
BLAKE2b-256 036c8098b2826a5de0300caaf1e71848f4277844b5e63de8030335d88387948b

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec907dabd4723948f80a0985d7bcfc7f46ab577b4145e98744cb05065476bf22
MD5 99207bdd9eb6033907c81835429ec5e3
BLAKE2b-256 2a28841495b3cb3ec662814e3e2a576e1e7ae0e8782a347a09b222d178b48ff7

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 60efcdf4d31da2d320eeda0023e3d3c589bbc7aa8ff24755113241de9af3caba
MD5 d74a15227077b64810565d27a327205d
BLAKE2b-256 e01aa213010ad7fd14ecca18f79236500c91bbcfacf2cd9195c80300b746e664

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 2655d0891c1f292e686dd3e648de92ef56c55543b1d77653df3044e8cfdc0b68
MD5 b1482941dd1b3b5c3f20863cfc11f810
BLAKE2b-256 cb979f3be30802eca71933fe0e5289b3153b90820a1197c0fe8669f9cd61a8d6

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp310-cp310-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp310-cp310-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3ed0aba1888308552aa2fb34484f9f88b82e5c29614121a29acb44165b86c965
MD5 65b096a65ae76b1705f77a126043131c
BLAKE2b-256 c4a53b9348474acbc562dbc6c59bd26e186453aaebc47bdb99834423de7eff0d

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c0cb2c721eba0dd421ba43c9d9fe0b5ddb2efd4f58eca9fbc7855e249e56a089
MD5 3c357e6aaf3db3430c7fdfab50ca7cf8
BLAKE2b-256 a72ceaf3ae14412c4d1be85cbe3a4f93f3985de55dfeeeeb70ed366cf472584e

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57c4538a3fe9f24281c3fbf0d90b53df5f619c04c661a8e9a460eb4989b9c670
MD5 e021f8486bdfb1155920753eb6044c03
BLAKE2b-256 7156b41fdafbcb5a0b7feae86536c867f2ffd1a043ef22575857604843d39528

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eaac9f67d1b77a18bf832051e57752189e7b93f08abf8d7efdf5b18d1aacf488
MD5 8d38115d86f3fee475d5a0789859e4c6
BLAKE2b-256 3e0f5f434e2a7899049208b759ab330cff8d3c7c44b2a691f755bed3e5181c3f

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 14057139e00212a006d566e42933566c6997452075bfa30913c93d6106e99432
MD5 d6fc6b6157c6f255a3438619d070ba5e
BLAKE2b-256 d0f4a963ea9735d4e951ba39746d89c9a0056061a0f53de0f17e6121caa9f64e

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b60cd1529aa39f976e4f9ebe4f3bd07b6ee2d81422bf4d3d150ac02967cabc9d
MD5 5c2cbfb294c150a185da19d4d49cb5bc
BLAKE2b-256 b55ff39f7e1c576c67d70ff0cbf7ac28453d7b5a51b21c3a39ada8048ccdd9a1

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 295243c849025f746fca96372a60484e39d1caf650b4a3a906b08a57c3118d94
MD5 bf30788a36baaae09e6540cb0abd3fed
BLAKE2b-256 4a323bbf8215fa6970c77e19d8eb85a6cb773c2be9a528a8eaed5624f1e7878b

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 51f1c87b9f31927240b59659949b4f6e3e8cd2e919d457f35cef4b8ac411c164
MD5 ba4dad6470fb22bb0cf2617d385a655e
BLAKE2b-256 1ebe58de679ed14e60007c270d1b5237035c5951e2ca6a4a0ecbe2d1b677bba7

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 53c3eaaec8342291200da8f52f75b545f7b73f627079576d840a6447da753988
MD5 7d4bb078a54e740ca5cc099f46d15958
BLAKE2b-256 6a80a4be8e164fcf4f3075b3bcc6a3d4e9a48fff26f63ff6ee780c9dcc94f348

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp38-cp38-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b6c44bde8d791c1d640f9c57af13e7050af92e010707c39bd00f2f0f56b8a4c1
MD5 c1123844d82379d5d8d922c12078d2b8
BLAKE2b-256 6122911807354e76752b08036ab798a72970213ce9bdf33d0d9464399fdf2313

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 eb300c7f50686cd3aabcb09adb5e8b5d92247298aedabc4a51acc72ca188e9f1
MD5 b4e0501939afa0e6699b95d8e0f5d731
BLAKE2b-256 3d137b0d1530983c6d6824f20ecdd1216a7a01e90e1972ab1b824e50631a7922

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b46296a6e128ef4ad1e113da7723888c30ff14fbe13ca55c370f015dac6415cd
MD5 ad219c4028d29b23f9c76b34aae6da44
BLAKE2b-256 4c5bfab856eb7933e0d45ab352405ff84f905070d056ae7bbdb1e2b71ecce818

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d92c69d5df983e73bccfa92b0577e5197adfad6fb9c13fa01ed830e169148b7b
MD5 a3fbb8deb3518adbc1212e587bfa347b
BLAKE2b-256 ff6187230a5b87a1a03c3b429c41b502970991290c33d7ec04559a21d6647fef

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 beb3c926ddcf4f7a99367b807c107f73161700d3f4c20c5ae94cbe4d6c6a479e
MD5 d0c71623345e98c89696cf5e9dd0b3e6
BLAKE2b-256 6e45405cdda6cc3c493a46e7b3692a390a9e2c120d8d98387393877c6db45d9b

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 23ee92bd7d318a02770c3327b76e84c97b6ea690d684d83481b83db62e41a802
MD5 e63d2953de4b89d83799b78172d10c34
BLAKE2b-256 53b51f7b6611378be2fd55967d2770998df16cd5e21c779cd37313ae9e9a0c2d

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c4253ea25cc2f044b5b418c04902b7bbd16e80583d4265ef87ed23ae4128274f
MD5 5087879282bb7b04de9e927ac509c085
BLAKE2b-256 e895d3e6c3301929c6cd8a3d7ff40ae6ac277c15ebdd69d40378ab03153e9879

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f1a44839eefbe0bc0d4e403e1655622034cc9394b3091eb80de31a40caafef7
MD5 ee82003c363ace10487e6c9549babe60
BLAKE2b-256 5914177754243df42b1dcaf95eb95c89390662ef449c4789066dde6feb8adeb6

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ac8737c9ca5764fd67205225dea47db74a23a6d5873f80f9cdfe6225a718cc8f
MD5 7061fb2cbe7084123a15b25c30950768
BLAKE2b-256 3fe382f686a0032d32bf77f5ef308b1cb1eac78057191ce9017b33824ad3eee4

See more details on using hashes here.

File details

Details for the file python_prtree-0.5.12-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_prtree-0.5.12-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 44c315c192b54f74d5d91fa4ce03dac5a87efa18315f8f8ce69b6fa9460aece8
MD5 10873c632d0056d56df2f457d7ed77d6
BLAKE2b-256 f6915a423e355c9fd34465602ec76c80fd2399aa767186d96b12983ef7451e6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page