Skip to main content

Spatial Polars

A package that extends polars for working with geospatial data.

Spatial polars relies on polars, shapely, pyogrio, geoarrow-python, and pyproj for I/O and processing.

Spatial polars uses lonboard for displaying geospatial data on an interactive map

Spatial polars is mostly just glue code connecting the work of others to bring spatial funcitonality to polars.

Documentation

Documentation can be found here: https://atl2001.github.io/spatial_polars/

Lazily access data

Spatial polars scan_spatial function will scan geoparquet files and any other data source supported by pyogrio and return a polars lazy frame. A read_spatial function is also provided which simply wraps scan_spatial with a .collect() at the end to return a polars dataframe. The scan_spatial function was the reason this package was created, it is much preferred over the read_spatial function for the same reasons that polars recommends using the lazy API over the eager API.

Geometry

When reading data from a spatial data source, the geometries are stored in a polars struct, with one polars binary field holding the geometry of the feature as WKB and another polars categorical field which stores the coordinate reference system as WKT. Storing the geometries in this manner has an advantage over using a polars binary field holding EWKB, because this allows spatial polars to work with custom projections which do not have a SRID, without a need to store custom SRID codes/CRS definition elsewhere.

All geometries in a single column are expected to have the same CRS, currently there is nothing enforcing or validating this.

Spatial polars allows you to intermix geometry types (eg. points and lines) in the same geometry column. Attempting to write a dataframe with a geometry column that has mixed geometry types may produce an error if the format is not capable of handling more than one geometry type.

Spatial Expressions

Many expressions are included which work with the geometry struct to convert the data in the polars series to a numpy array of WKB, then convert the array of WKB to shapely geometry objects, and then use shapely's functions to do the spatial operation, then if the result is an array of geometries, they will be converted back to WKB and stored in a struct with the same CRS as the input. Shapely functions that return something which is not a geometry will result in an appropriately typed polars series. Spatial polars expressions can be accesssed under the .spatial namespace or directly from the SpatialExpr class. When accessing the expressions thru the SpatialExpr class type hints will be available.

Spatial expressions which use more than one geometry

Expressions in polars require a single column as the input. For computations involving two geometries, if the computation should be applied to the geometries in the column and a single other geometry, that geometry can be supplied to the expression as a scalar. However if the computation needs to be run between two geometries each coming from different column in the dataframe, the two geometry struct columns must be placed into a single struct which is then supplied to the spatial polars expression.

Motivation

Spatial polars was motivated by interest in polars IO plugins, and wanting to be able to easily read data from geopackages and GPX files into a polars dataframe.

Thank you!

This project would not be possible without all the work from the maintainers/contributors of of all the packages it's built on listed above, along with all the code they're built on, and inspired by.

Metadata

Release files for spatial-polars 0.5.1

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

Source distribution (sdist)

Source distribution for spatial-polars 0.5.1
File Size Uploaded Provenance Actions
spatial_polars-0.5.1.tar.gz 20.1 MB Without provenance Details for spatial_polars-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for spatial-polars 0.5.1
File Actions
spatial_polars-0.5.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for spatial_polars-0.5.1-cp39-abi3-win_amd64.whl
spatial_polars-0.5.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for spatial_polars-0.5.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
spatial_polars-0.5.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for spatial_polars-0.5.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
spatial_polars-0.5.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for spatial_polars-0.5.1-cp39-abi3-macosx_11_0_arm64.whl
spatial_polars-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for spatial_polars-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 42.5 MB

Release files / spatial_polars-0.5.1.tar.gz

Download URL spatial_polars-0.5.1.tar.gz
Size 20.1 MB
Tags Source
SHA-256 checksum
How to use checksums
db23c12233e8de1af006cd83c892a048ded51d753dd994d781e3cce197eec457
BLAKE2b-256 checksum
How to use checksums
972aa193c025bb9782a47cbde9dde81530cf7f0b2707e2849b944b4511cad7b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / spatial_polars-0.5.1-cp39-abi3-win_amd64.whl

Download URL spatial_polars-0.5.1-cp39-abi3-win_amd64.whl
Size 4.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4298fc674b25191f5b4d71613ad2c598fb733139c9ba216e894658beb090ed45
BLAKE2b-256 checksum
How to use checksums
c1f4c19cca891aa0c63827ba648c74b22db3d06286d32baf0add1daa0c3a2d86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / spatial_polars-0.5.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spatial_polars-0.5.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.9 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ecae2f0f2fe856e9eee39084779b970ca542266cdb3c2587d33a6fb26b9244bf
BLAKE2b-256 checksum
How to use checksums
f253e1216ab574abdf9f2d3ad0bc06555980df86686c1792bdc6eb28aa54cf14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / spatial_polars-0.5.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL spatial_polars-0.5.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 4.8 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
da3d3571965b0d142e5602f7a1fc65922eb9a33502f6668e08c77079686a774c
BLAKE2b-256 checksum
How to use checksums
69f5311f0d44cba76ab6180efccf9cb1ccaac103e369dca0396aea6f07e7b1eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / spatial_polars-0.5.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL spatial_polars-0.5.1-cp39-abi3-macosx_11_0_arm64.whl
Size 4.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e621618c299d3a921b3b662577f2b27151483eb3d093bdb8da68c2c186018865
BLAKE2b-256 checksum
How to use checksums
9935dc600fd84c7adff4317469da701c2bb359eb9fc563d3b36648b421853de4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / spatial_polars-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL spatial_polars-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 4.2 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9d3fffb65e386f719172e590f16d5425267464072e393c60299a6f6bb9657ca8
BLAKE2b-256 checksum
How to use checksums
81b0723f495d3b9c41e499624b203c033487a72927ef4583d77cc9bab4771b83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Security for spatial-polars 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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