Geospatial query engine with dynamic index selection
Project description
A geospatial query engine for optimized in-memory queries. Rust core, Python API.
Background
GeoPandas spatial queries (kNN, bounding-box range, point-in-polygon) default to linear scans, and even optimized baselines like the GeoPandas STRtree or scipy KDTree require manual index selection and still carry Python-level overhead.
PyCanopy is a dedicated spatial query engine that inspects your dataset at load time (size, geometry type, spatial distribution) and automatically picks the fastest index (KD-tree, R-tree, uniform grid, or brute force).
Preliminary Performance Comparison
Measured on 1 million geometries against GeoPandas STRtree / scipy KDTree. Three scenarios used: uniform distribution, clustered distribution queried in a dense region, and clustered distribution queried in a sparse region.
Points
| Query | Scenario | PyCanopy | GeoPandas sindex | Speedup |
|---|---|---|---|---|
| kNN k=10 | Uniform | 0.03 ms | 0.57 ms scipy KDTree | 17x |
| kNN k=10 | Clustered, dense | 0.03 ms | 0.13 ms scipy KDTree | 4x |
| kNN k=10 | Clustered, sparse | 0.01 ms | 0.18 ms scipy KDTree | 14x |
| Range 1% bbox | Uniform | 1.27 ms | 6.50 ms STRtree | 5x |
| Range 1% bbox | Clustered, dense | 1.41 ms | 25.61 ms STRtree | 18x |
| Range 1% bbox | Clustered, sparse | 0.01 ms | 0.12 ms STRtree | 24x |
Polygons
| Query | Scenario | PyCanopy | GeoPandas sindex | Speedup |
|---|---|---|---|---|
| Range 1% bbox | Uniform | 0.63 ms | 4.67 ms STRtree | 7x |
| Range 1% bbox | Clustered, dense | 8.40 ms | 22.73 ms STRtree | 3x |
| Range 1% bbox | Clustered, sparse | 0.00 ms | 0.09 ms STRtree | 37x |
| Contains | Uniform | 0.01 ms | 0.04 ms STRtree | 4x |
| Contains | Clustered, dense | 0.04 ms | 0.08 ms STRtree | 2x |
| Contains | Clustered, sparse | 0.01 ms | 0.03 ms STRtree | 5x |
Installation
pip install pycanopy
Pre-built wheels for Linux, macOS, and Windows. No Rust toolchain required.
Quick start
import numpy as np
from pycanopy import Engine
# Point dataset
coords = np.random.uniform(0, 100, size=(500_000, 2))
engine = Engine(coords)
nearest = engine.knn(x=42.0, y=37.0, k=10)
in_box = engine.range_query(min_x=10.0, min_y=10.0, max_x=50.0, max_y=50.0)
# Polygon dataset
from shapely.geometry import box
polygons = [box(i, 0, i + 0.9, 0.9) for i in range(500_000)]
poly_engine = Engine.from_polygons(polygons)
intersecting = poly_engine.range_query(0.0, 0.0, 10.0, 1.0)
containing = poly_engine.contains(x=5.5, y=0.5)
Accepted input formats
| Format | Example |
|---|---|
numpy (N, 2) array |
np.array([[x, y], ...]) |
| GeoArrow PyArrow array | pa.StructArray or FixedSizeList<2> |
geopandas GeoSeries |
gdf.geometry |
| list of shapely Points or Polygons | [Point(x, y), ...] |
list of (x, y) tuples |
[(x, y), ...] |
| Separate coordinate sequences | Engine.from_coords(xs, ys) |
Index selection
PyCanopy inspects the dataset at load time and picks automatically:
| Condition | Index |
|---|---|
| N < 500 or selectivity > 50% | Brute force |
| Points + kNN | KD-tree |
| Points + uniform distribution + range | Uniform grid |
| Points + clustered distribution + range | KD-tree |
| Polygons or mixed geometries | R-tree |
Development setup
Requires Python ≥ 3.9 and a Rust toolchain (rustup.rs).
git clone https://github.com/pranav-walimbe/pycanopy
cd pycanopy
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]" maturin shapely geopandas
maturin develop
pytest
cargo test
License
MIT
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycanopy-0.2.0.tar.gz.
File metadata
- Download URL: pycanopy-0.2.0.tar.gz
- Upload date:
- Size: 172.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e758a93be3b852118869cfdaca3700526972d5a8eae8e15c08ea73f28ced8b82
|
|
| MD5 |
962522ffa15240cbca9917fef4d4d405
|
|
| BLAKE2b-256 |
5c0ce89cdcb0ba4740ce0a8751bfc691d28faa0de43803f5f398dcf89b8f6a6b
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0.tar.gz:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0.tar.gz -
Subject digest:
e758a93be3b852118869cfdaca3700526972d5a8eae8e15c08ea73f28ced8b82 - Sigstore transparency entry: 1706323165
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycanopy-0.2.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: pycanopy-0.2.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 260.7 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63e924ad2d03b082d97d927fe309eed9863317b56a632a23a171f2c0176ac50f
|
|
| MD5 |
0290955581b54de27bc77ae22b8c1b01
|
|
| BLAKE2b-256 |
1e5b6abe117ace650d0668375719bb0a83d956772dab255bcb7044c6a79ce0f9
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0-cp39-abi3-win_amd64.whl -
Subject digest:
63e924ad2d03b082d97d927fe309eed9863317b56a632a23a171f2c0176ac50f - Sigstore transparency entry: 1706323414
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 384.0 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5cfbc7fbc677481c34d29432eadd27864f95e378d1044953eb156b437fcf63c
|
|
| MD5 |
d6090f9f9dc74a837131981ead079336
|
|
| BLAKE2b-256 |
dfbdf61aad69f670c06e9f8f6e526ef6fae1fd45445a2284549f4d587975872f
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b5cfbc7fbc677481c34d29432eadd27864f95e378d1044953eb156b437fcf63c - Sigstore transparency entry: 1706323308
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 373.2 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09bf6fbf409dcb8f70d56df01d086ae183dfe88367259840fc9db15c8a819d1c
|
|
| MD5 |
d92cf393a54666bfcf122b9a20dba509
|
|
| BLAKE2b-256 |
44159f9773f1da6755026111e104a8231709dd4e400651c317c267edbe1ad623
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
09bf6fbf409dcb8f70d56df01d086ae183dfe88367259840fc9db15c8a819d1c - Sigstore transparency entry: 1706323521
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 337.5 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d589aa5508bb69d8110edf7e2221bd3903d091fec4db8ce6f40197c25c8aed0
|
|
| MD5 |
6eda3323a24b5bd538ce4bb834966dcd
|
|
| BLAKE2b-256 |
57a6d3e277dbfd807d21ed7b251b2e6cdf5eef1d05c3ef7271d096ecb33765ed
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
0d589aa5508bb69d8110edf7e2221bd3903d091fec4db8ce6f40197c25c8aed0 - Sigstore transparency entry: 1706323237
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 354.8 kB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7dc0b4bf93a87d474397b06ae1b58aca79f72bad04a5c95f13bc23ab00e87fa
|
|
| MD5 |
424a942e29b2a64032ae070fa19216f5
|
|
| BLAKE2b-256 |
ddce0de34551ae76953a4295c6d489b7783c617c9105ff553ccf5c36f273feee
|
Provenance
The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on pranav-walimbe/PyCanopy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
d7dc0b4bf93a87d474397b06ae1b58aca79f72bad04a5c95f13bc23ab00e87fa - Sigstore transparency entry: 1706323609
- Sigstore integration time:
-
Permalink:
pranav-walimbe/PyCanopy@825ecf8afc39234c514baca0200feeb1d1918487 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/pranav-walimbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@825ecf8afc39234c514baca0200feeb1d1918487 -
Trigger Event:
push
-
Statement type: