Skip to main content

Pyqtree is a pure Python spatial index for GIS or rendering usage. It stores and quickly retrieves items from a 2x2 rectangular grid area, and grows in depth and detail as more items are added. The actual quad tree implementation is adapted from Matt Rasmussen’s compbio library and extended for geospatial use.

Platforms

Python 2 and 3.

Dependencies

Pyqtree is written in pure Python and has no dependencies.

Installing It

Installing Pyqtree can be done by opening your terminal or commandline and typing:

pip install pyqtree

Alternatively, you can simply download the “pyqtree.py” file and place it anywhere Python can import it, such as the Python site-packages folder.

Example Usage

Start your script by importing the quad tree.

from pyqtree import Index

Setup the spatial index, giving it a bounding box area to keep track of. The bounding box being in a four-tuple: (xmin, ymin, xmax, ymax).

spindex = Index(bbox=(0, 0, 100, 100))

Populate the index with items that you want to be retrieved at a later point, along with each item’s geographic bbox.

# this example assumes you have a list of items with bbox attribute
for item in items:
    spindex.insert(item, item.bbox)

Then when you have a region of interest and you wish to retrieve items from that region, just use the index’s intersect method. This quickly gives you a list of the stored items whose bboxes intersects your region of interests.

overlapbbox = (51, 51, 86, 86)
matches = spindex.intersect(overlapbbox)

There are other things that can be done as well, but that’s it for the main usage!

More Information:

License:

This code is free to share, use, reuse, and modify according to the MIT license, see LICENSE.txt.

Credits:

  • Karim Bahgat

  • Joschua Gandert

Changes

1.0.0 (2018-09-14)

  • Bump to first major version

  • Fix so returns list instead of set

  • Support inserting hashable items

0.25.0 (2016-06-22)

  • Misc user contributions and bug fixes

0.24.0 (2015-06-18)

  • Previous stable PyPI version.

Release files for Pyqtree 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Pyqtree 1.0.0
File Size Uploaded
Pyqtree-1.0.0.tar.gz 5.2 kB Details

Release files / Pyqtree-1.0.0.tar.gz

Download URL Pyqtree-1.0.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4f36d5160ddf170d7245e9c7102a45211b85003383dd552b6cd109e50cc3af81
BLAKE2b-256 checksum
How to use checksums
df902905247e80944d2ce6b36a69fb995709cef25c409018f7471fd88cc1122a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.24

1 release file

0.23

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page