Skip to main content

Spatial extension for Polars DataFrames

Project description

Banner

Polars ST

Polars ST provides spatial operations on Polars DataFrames, Series, and Expressions. Just like Shapely and GeoPandas, it make use of the GEOS library, meaning that its API is mostly identical to theirs.

>>> import polars_st as st
>>> gdf = st.GeoDataFrame({
...     "category": ["A", "A", "B"],
...     "geometry": [
...         "POLYGON((0 0, 0 4, 4 2, 0 0))",
...         "POLYGON((4 0, 4 4, 0 2, 4 0))",
...         "POLYGON((0 0, 2 2, 2 0, 0 0))",
...     ]
... })
>>> gdf = gdf.group_by("category").agg(st.intersection_all()).with_columns(area=st.area())
>>> gdf.with_columns(st.to_wkt())
shape: (2, 3)
┌──────────┬─────────────────────────────────────┬──────┐
│ category ┆ geometry                            ┆ area │
│ ---      ┆ ---                                 ┆ ---  │
│ str      ┆ str                                 ┆ f64  │
╞══════════╪═════════════════════════════════════╪══════╡
│ B        ┆ POLYGON ((0 0, 2 2, 2 0, 0 0))      ┆ 2.0  │
│ A        ┆ POLYGON ((4 2, 2 1, 0 2, 2 3, 4 2)) ┆ 4.0  │
└──────────┴─────────────────────────────────────┴──────┘

Installation

Polars ST is published on PyPI so you can install it with your preferred package manager.

pip install polars-st

How it works

Geometries are stored as EWKB in regular Polars Binary columns. EWKB is a extension to the WKB standard popularized by PostGIS, that can also store information about the CRS of each geometry as an integer code called SRID.

For every spatial operations, the WKB binary blob will be parsed into a Geometry object so the operation can be done. If the operation result is a geometry, it will then be serialized back to EWKB. Because of that round-trip, some operations might turn out to be slower than GeoPandas. In most cases however, the performance penalty of that round-trip will be marginal compared to the spatial operation, and you will fully benefit from the parallelization capabilities of Polars.

About GeoPolars

GeoPolars is an very promising tool for manipulating geographic data in Polars based on GeoArrow that likely will outperform this library's performance. It however seems to be quite a long way from being ready and feature-complete, mostly due to Polars lack of support for Arrow Extension Types and subclassing of core datatypes.

polars-st stores geometry as EWKB in regular Binary columns and delegates core functionality to GEOS, which allows it to be ready now, with full support for 3D / 4D coordinates, curved geometry types (CircularString, CurvePolygon, ...) and per-geometry CRS information.

About Polars

This project is not affiliated with Polars. The design language was deliberately made very close to that of Polars to highlight the fact that this project is an exclusive extension to Polars, and as a tribute to its effectiveness.

About GEOS

In order to save myself (and yourself) from the burden of GEOS version-specific features and bugs, polars-st statically link to GEOS main. This means that all documented features are guaranteed to be available. This also means that this project is LGPL licensed, the same way GEOS is.

License

Copyright (C) 2024 Aurèle Ferotin

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

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

polars_st-0.1.0a28.tar.gz (178.3 kB view details)

Uploaded Source

Built Distributions

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

polars_st-0.1.0a28-cp39-abi3-win_amd64.whl (6.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

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

polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a28-cp39-abi3-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.1.0a28-cp39-abi3-macosx_10_12_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file polars_st-0.1.0a28.tar.gz.

File metadata

  • Download URL: polars_st-0.1.0a28.tar.gz
  • Upload date:
  • Size: 178.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for polars_st-0.1.0a28.tar.gz
Algorithm Hash digest
SHA256 0336048be06dab95b304f1549d937d8dbc2c8647130b324995b750e2e131e58d
MD5 c052c6124eb970620fe41ba67468e4ed
BLAKE2b-256 8ec9e52483c2bd70137b835c653864bf2d8d3ecb10df12c467158dad830fb046

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a28-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a28-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 877119b1d4bc4d1a699abb9ef96a3ee6a8537a94c3883d39effd7b64c76e74a3
MD5 fddd30efef6b8f0b2fd33fbac2fe601d
BLAKE2b-256 0897879071eb3e98d4a64ce942e9dca32ee3c285706ffaf091060f8a6639dae7

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1cbc4ef8175afa2069bb7d0015afb133d911c2f9cbe3b5023ce3065525df6760
MD5 4c1621bea95eb13cbf192a3404bd3b5e
BLAKE2b-256 398e72987948b964d7192316156423e549177869758ee02fdf6725bd9290d762

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a28-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a7f365aded68b2f5d82cac88e4a11d7aba3b40aabc27ea42a73f629b8e39cc6f
MD5 bee575ad3e0e9aba1cc4fddfaa7bd0d9
BLAKE2b-256 976c6275f99fafb587b723e9075c2ccde89a367e8563c735391f8876eb5ef814

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a28-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a28-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab289576263dac7bbf21197711868169754e40899e98769f89692ac742f15e06
MD5 33a235b62e6dbb91376fdd055a34b78b
BLAKE2b-256 957c60e93e16ef834610967073ed211100ecf512c77e34631ae2a3e0a5d3708f

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a28-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a28-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0424f4e3ed881364807524833dc275cbac3abee702a188f57fc87184978306b4
MD5 e8e179bbe83506bbb4df6a91430b49bb
BLAKE2b-256 3cc26c01ebf2b47fe5a4b19e7ef8202669534deb0bee265629045f9fcad4d7e9

See more details on using hashes here.

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