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 also stores information about the CRS of each geometry as an integer code called SRID.

For every spatial operations, the WKB 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 WKB. Because of that round-trip, some operations might turn out to be slower than GeoPandas. In most cases however, the performance penalty will be marginal 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 the GeoArrow specification. 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 Z / M coordinates, curved geometry types (CircularString, CurvePolygon, ...) and Series with mixed geometry type and SRIDs.

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 is an exclusive extension to Polars, and as a tribute to the effectiveness of the original design.

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.7.0.tar.gz (255.9 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.7.0-cp39-abi3-win_arm64.whl (42.9 MB view details)

Uploaded CPython 3.9+Windows ARM64

polars_st-0.7.0-cp39-abi3-win_amd64.whl (49.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.2 MB view details)

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

polars_st-0.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (41.9 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.7.0-cp39-abi3-macosx_11_0_arm64.whl (49.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl (52.4 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file polars_st-0.7.0.tar.gz.

File metadata

  • Download URL: polars_st-0.7.0.tar.gz
  • Upload date:
  • Size: 255.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for polars_st-0.7.0.tar.gz
Algorithm Hash digest
SHA256 569d8a40b549e0856d78ba61aa602fe02b086272338dfeb61e12788b8b9e3d6a
MD5 6193c398f9425311d25b984a234377f4
BLAKE2b-256 14f6d00b98f9a25fa402be787ab055afd355543cd07e7b4c8036eee66643139b

See more details on using hashes here.

File details

Details for the file polars_st-0.7.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: polars_st-0.7.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 42.9 MB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e25c6243da92a3c5e8391346a1c3ca2bf145d30669c58e8008e06dba52c67b16
MD5 d0e1b49ded3e72e32487db9be40d8716
BLAKE2b-256 b05e2aa214cd333e09d0e55002e729d59eb86a58e9e66e302a9bfa17090b4ac9

See more details on using hashes here.

File details

Details for the file polars_st-0.7.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: polars_st-0.7.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 49.5 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8aa7910cf640aa75033cfcab96b825ff05179dea6ed19a0b6204ece9b1bba9da
MD5 36bb00b3b49d240a5eaecdcdd4af70ae
BLAKE2b-256 205282a76f1ec2b78eb2c474249649247e268f6e1a043d13cb7d8d8b16b5d099

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 299e394e7d3956df1ab021c2ca4860a1c72266c03162fc3cd0b44f5b622cb088
MD5 84861667e0977f52841c613648534669
BLAKE2b-256 b3686b46ce77a0d961e8c1935dfca608980514c84ee2b8cf7874090eea19eedc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0a901e2219a281180adcd97ccc853fc69d867b52c4077d93fa95591c1e776e98
MD5 125bb33ce8ce20cfa84da5c213909923
BLAKE2b-256 33e352780ccd74c45ad0232b3b596c5ab2bec613385eea9c97d0fb8743d30ce5

See more details on using hashes here.

File details

Details for the file polars_st-0.7.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf3bbd26a3844bf2a5a608c0f31fe007314b63e440ff74d19881c55297638be0
MD5 da71743c089467877e8a384a41044136
BLAKE2b-256 1ec047274496c4164f1c4541060db093d017393dab61537ad6bd1ae7f3bdeaa1

See more details on using hashes here.

File details

Details for the file polars_st-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.7.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c831838e574314e8e2b6e5c540484f01de5e0c0c20a78c65ee7be63c2f84cc80
MD5 8392e63beab3a35a8e8854d2dd554266
BLAKE2b-256 8ca0c80b0aecebf958d8be7dff305fcfcf6deffa2b1087fda508b3c80b904949

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