Skip to main content

A package that extends polars for working with geospatial data.

Project description

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.

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

spatial_polars-0.2.3.tar.gz (20.1 MB view details)

Uploaded Source

Built Distribution

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

spatial_polars-0.2.3-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file spatial_polars-0.2.3.tar.gz.

File metadata

  • Download URL: spatial_polars-0.2.3.tar.gz
  • Upload date:
  • Size: 20.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spatial_polars-0.2.3.tar.gz
Algorithm Hash digest
SHA256 fba0d4696e70835f74bd3929aa8b13bf97733e4c3fe6e2244b965c3784edeb36
MD5 1a1d5ad2fad2c95b9d0d9e36d9d184c4
BLAKE2b-256 495e79dc6faae33490521d17c48f2d3f164a01038c25fc85f709286a0dfbcc50

See more details on using hashes here.

Provenance

The following attestation bundles were made for spatial_polars-0.2.3.tar.gz:

Publisher: publish_to_pypi.yml on ATL2001/spatial_polars

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

File details

Details for the file spatial_polars-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: spatial_polars-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spatial_polars-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cecd3dc547a08ef44b974b8d1dbc4cf22bedcc7388c30634e2dc068da136939a
MD5 fbfa97622d371c400d6c44c36c8921b7
BLAKE2b-256 ff412c3084977ad6480bdadb8259d11d0870cd4bf6e48bc1ccf417d13f45fabf

See more details on using hashes here.

Provenance

The following attestation bundles were made for spatial_polars-0.2.3-py3-none-any.whl:

Publisher: publish_to_pypi.yml on ATL2001/spatial_polars

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