Skip to main content

Geospatial query engine with dynamic index selection

Project description

PyCanopy

PyPI version Python versions CI License: MIT

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

pycanopy-0.2.0.tar.gz (172.0 kB view details)

Uploaded Source

Built Distributions

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

pycanopy-0.2.0-cp39-abi3-win_amd64.whl (260.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (384.0 kB view details)

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

pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (373.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (337.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (354.8 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

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

Hashes for pycanopy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e758a93be3b852118869cfdaca3700526972d5a8eae8e15c08ea73f28ced8b82
MD5 962522ffa15240cbca9917fef4d4d405
BLAKE2b-256 5c0ce89cdcb0ba4740ce0a8751bfc691d28faa0de43803f5f398dcf89b8f6a6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.2.0.tar.gz:

Publisher: release.yml on pranav-walimbe/PyCanopy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pycanopy-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 63e924ad2d03b082d97d927fe309eed9863317b56a632a23a171f2c0176ac50f
MD5 0290955581b54de27bc77ae22b8c1b01
BLAKE2b-256 1e5b6abe117ace650d0668375719bb0a83d956772dab255bcb7044c6a79ce0f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on pranav-walimbe/PyCanopy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycanopy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5cfbc7fbc677481c34d29432eadd27864f95e378d1044953eb156b437fcf63c
MD5 d6090f9f9dc74a837131981ead079336
BLAKE2b-256 dfbdf61aad69f670c06e9f8f6e526ef6fae1fd45445a2284549f4d587975872f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pycanopy-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 09bf6fbf409dcb8f70d56df01d086ae183dfe88367259840fc9db15c8a819d1c
MD5 d92cf393a54666bfcf122b9a20dba509
BLAKE2b-256 44159f9773f1da6755026111e104a8231709dd4e400651c317c267edbe1ad623

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycanopy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d589aa5508bb69d8110edf7e2221bd3903d091fec4db8ce6f40197c25c8aed0
MD5 6eda3323a24b5bd538ce4bb834966dcd
BLAKE2b-256 57a6d3e277dbfd807d21ed7b251b2e6cdf5eef1d05c3ef7271d096ecb33765ed

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pycanopy-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d7dc0b4bf93a87d474397b06ae1b58aca79f72bad04a5c95f13bc23ab00e87fa
MD5 424a942e29b2a64032ae070fa19216f5
BLAKE2b-256 ddce0de34551ae76953a4295c6d489b7783c617c9105ff553ccf5c36f273feee

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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