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.1.2.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.1.2-cp39-abi3-win_amd64.whl (260.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

pycanopy-0.1.2-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.1.2-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.1.2-cp39-abi3-macosx_11_0_arm64.whl (337.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pycanopy-0.1.2-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.1.2.tar.gz.

File metadata

  • Download URL: pycanopy-0.1.2.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.1.2.tar.gz
Algorithm Hash digest
SHA256 fa9b6b73ccecc0fd0c896fef696d5372531257afb663855bc5178aeb2ad4a66b
MD5 17e573eac6893b66e04894965fe0356f
BLAKE2b-256 80f83f7aa902dadde65c17d80cac5b18fce32d2cdb03291330e7620ea48e580f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2.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.1.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pycanopy-0.1.2-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.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2a1c718b927fd1b6f76b9961aaa0cc3f017efc6f473415df7f62325bc6488b91
MD5 948cea80409b8ae90af5fe3dce83460e
BLAKE2b-256 3e99fe9c0d4518633475fa98d264e08b555425e39cf4776d1cc1cf83333d1ce1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2-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.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycanopy-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69c0b57ebcc31d4e4725dd465ac6fc4ba38c7a96c140a58c3f6c008f94d3fa46
MD5 f9b0a290599f704ccdaac3680ec2242d
BLAKE2b-256 b03d935e8c76f1cab5531c3789757569bd712985d7c7458812086ca7c5d96854

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2-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.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pycanopy-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef764d2482fa8c22424034065072ee1d52220af1159a871600e75d7e5c875d42
MD5 bb248bb77f54014a13813bb9e1e50ef0
BLAKE2b-256 9c5f50ca98757ea62197a46665a14b0b23203989dec5950f21621c62e2916187

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2-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.1.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycanopy-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a782b58e280455cc6344155378e3c834fab1be606161acb68543ddd40a707ed8
MD5 d00ef53fb91d43d70042bf5b8385dcbb
BLAKE2b-256 898b9e29e627c3073e9682578d98e7d542a867605840ade5154bb0381887f54a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2-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.1.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pycanopy-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 db737c599d9e166612538eebf7bbcf0f49b47e968b4315a8305498053e6a75e5
MD5 96f588f487de51173be7cc349d6da5aa
BLAKE2b-256 026fc9199018b2f5bf87f75d78c000ac311dfc437d9984e64feca11170655ac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycanopy-0.1.2-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