Skip to main content

PySpart

License Python Version PyPI

Python bindings for the Spart library.

Installation

pip install pyspart

Examples

Below are some examples of how to use the different trees in PySpart.

Quadtree (2D)

from pyspart import Quadtree, Point2D

# Define the bounding area for the Quadtree.
boundary = {"x": 0.0, "y": 0.0, "width": 10.0, "height": 10.0}

# Create a new Quadtree with a maximum capacity of 3 points per node.
tree = Quadtree(boundary, 3)

# Define some 2D points.
point1 = Point2D(1.0, 2.0, "Point1")
point2 = Point2D(3.0, 4.0, "Point2")
point3 = Point2D(5.0, 6.0, "Point3")
point4 = Point2D(7.0, 8.0, "Point4")
point5 = Point2D(2.0, 3.0, "Point5")

# Insert points into the Quadtree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a k-nearest neighbor (kNN) search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Octree (3D)

from pyspart import Octree, Point3D

# Define the bounding area for the Octree.
boundary = {"x": 0.0, "y": 0.0, "z": 0.0, "width": 10.0, "height": 10.0, "depth": 10.0}

# Create a new Octree with a maximum capacity of 3 points per node.
tree = Octree(boundary, 3)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the Octree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Kd-tree (3D)

from pyspart import KdTree3D, Point3D

# Create a new Kd-tree for 3D points.
tree = KdTree3D()

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the Kd-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

R-tree (3D)

from pyspart import RTree3D, Point3D

# Create a new R-tree with a maximum capacity of 4 points per node.
tree = RTree3D(4)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the R-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

R*-tree (3D)

from pyspart import RStarTree3D, Point3D

# Create a new R*-tree with a maximum capacity of 4 points per node.
tree = RStarTree3D(4)

# Define some 3D points.
point1 = Point3D(1.0, 2.0, 3.0, "Point1")
point2 = Point3D(3.0, 4.0, 5.0, "Point2")
point3 = Point3D(5.0, 6.0, 7.0, "Point3")
point4 = Point3D(7.0, 8.0, 9.0, "Point4")
point5 = Point3D(2.0, 3.0, 4.0, "Point5")

# Insert points into the R*-tree.
tree.insert(point1)
tree.insert(point2)
tree.insert(point3)
tree.insert(point4)
tree.insert(point5)

# Perform a kNN search.
neighbors = tree.knn_search(point1, 2)
print(f"kNN search results for {point1}: {neighbors}")

# Perform a range search with a radius of 5.0.
range_points = tree.range_search(point1, 5.0)
print(f"Range search results for {point1}: {range_points}")

# Remove a point from the tree.
tree.delete(point1)

Check out the examples directory for more examples.

Serialization

In Python, you can use the save and load methods to serialize and deserialize the tree to and from a file:

from pyspart import Quadtree, Point2D

# Create a Quadtree and insert some points
boundary = {"x": 0.0, "y": 0.0, "width": 100.0, "height": 100.0}
qt = Quadtree(boundary, 4)
qt.insert(Point2D(10.0, 20.0, "point1"))
qt.insert(Point2D(50.0, 50.0, "point2"))

# Save the tree to a file
qt.save("quadtree.spart")

# Load the tree from the file
loaded_qt = Quadtree.load("quadtree.spart")

License

PySpart is licensed under the MIT License.

Download files

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

Source Distribution

pyspart-0.6.0.tar.gz (172.1 kB view details)

Uploaded Source

Built Distributions

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

pyspart-0.6.0-cp310-abi3-win_arm64.whl (332.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

pyspart-0.6.0-cp310-abi3-win_amd64.whl (361.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

pyspart-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl (439.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

pyspart-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl (402.6 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

pyspart-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (440.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

pyspart-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (406.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

pyspart-0.6.0-cp310-abi3-macosx_11_0_arm64.whl (381.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pyspart-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl (415.7 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file pyspart-0.6.0.tar.gz.

File metadata

  • Download URL: pyspart-0.6.0.tar.gz
  • Upload date:
  • Size: 172.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for pyspart-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4000a09cf8fcde880f10c65433b596092c0c73a992c9e99f5ea0a81809b2d33a
MD5 34fa638a3b2e0ce43427c2d355e2a779
BLAKE2b-256 18b3a0780245e211b8d55bc8c2f121133d326eddef8d6ecd7311d49e0d221d37

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: pyspart-0.6.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 332.4 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 17b129e8c6cc61a5019c608b50a7808b1c20eb3be1468f80b69bd1fd072e36c4
MD5 9d0f04c9a4de6f96b3d46459a353f961
BLAKE2b-256 ca1ca0153bd7250c2dd8b84f8c6b1fcd214514ff7e5916c7a09e6ec050898e95

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pyspart-0.6.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 361.4 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b5fadd4e80241f92b7735cbdff07b07897615cb23e024d2e2d399716be3e4f60
MD5 6d1c4ffc93715c2cec4275cc8a091f09
BLAKE2b-256 3266380cf2e1b4d8980954f64650ce3748fece5b8a1582a08c460929f1caff66

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 279781afa641e179727858d8e1c03dba939f3a6def3d15365cdf960240925d94
MD5 019c3cd76eb3cbdbcbe7e644cd9c60bb
BLAKE2b-256 cba129227b32bc89e1be6854b9d1d9f05f6da27e79d7db33e9e0642392cee427

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9d5be596ded2761ed9d488b32ba1ff626a5abe2071b7ea9e74a78045653bdda6
MD5 f33e69a0f9c06d30bf7feccc659459f3
BLAKE2b-256 c52a1b0145cfc8bb7a200a8b39976fe56a93c5ff9307bd357c1ce10b67b52096

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89b51033cb9d1de6bcd00322c380665b0f6ed20e8fc0b275c4948958f1a44c66
MD5 981799b68e0bb350f28172e56f2f7ba4
BLAKE2b-256 328b42b6a54c428a04da181454c7c7ef607a7338a5f2de3865d82b15449056a2

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1272b9507303f93a7189a551721124c6562c0015e4aa8ab61751b06b863bad99
MD5 a5f0e707a866bfdb13c28c0bce872137
BLAKE2b-256 d2b6819fc862f088606fb1ab5de04acb925dfd5562c416ccb59f92ca65ad2e74

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 634d98123d11650d1f61438b1c629d0b0bf8d36ef90456fbd26673ae4d43b4a4
MD5 8560c541f224e55cf983626974a1bf8e
BLAKE2b-256 dc2eacbe9419f491875e3356808d50cc473b633e0c61bd08c520785dbfeb07c0

See more details on using hashes here.

File details

Details for the file pyspart-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyspart-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 87292686d83b64e952bc7b8c126dcf29614796214c88e760d476b354c0007bab
MD5 482042611b193a8d39e0d1252448ae6b
BLAKE2b-256 b3ace1f38016f4ea778eeb6da7ff72c1e0d99ae7ffa4ac22c04f64185310c212

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.1

9 files

This release

0.6.0 This release

9 files

0.5.1

3 files

0.5.0

3 files

0.4.2

1 file

0.4.1

1 file

0.3.0

1 file

0.2.0

1 file

0.1.1

1 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