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.4.0.tar.gz (253.4 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.4.0-cp39-abi3-win_amd64.whl (44.1 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.4 MB view details)

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

polars_st-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (38.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.4.0-cp39-abi3-macosx_11_0_arm64.whl (44.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl (47.3 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.4.0.tar.gz
Algorithm Hash digest
SHA256 78c2f02f99d28214cb66c3a3d6c3c7f52c57597bdaf7a8f275a473619eaa4f1f
MD5 046038f26c27c33d929a86db81d2e480
BLAKE2b-256 8dd915318eac69dda00f35873007bfeb398e51199806e8abbe755393c1eda3c2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.4.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eeb1478645ed24200e3197b81ac87e0883251fe1fe57111f7d0de3d21ae68b82
MD5 e3dd77c1e4cacfeac2f724227afcc02a
BLAKE2b-256 21065c0ca2188b56dbce005a45217443dfa3048fc4c673c9b2bf37a4a46233a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 788b6693a9193ba44a8a32cb7fafa02ae8470b772cc1bc356e3f5fe71b7e6223
MD5 c92bc16d14df0fd5a2622ace8d621553
BLAKE2b-256 1579fdc310bd1f2576cc54e93deff4ed55c63b689d0be8b6554f7d69ccad4e4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 780adb0041328542f886d6c393f7ff72507d9cbc002a42be13e659a9af2fd70c
MD5 081133bfcf6aad17353985ffc7d5eb7a
BLAKE2b-256 bd7c9778057e6d843e7ab6adfbf602e8b266d67f5aeed59b421712ef4d958ab1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bba8ce3f60898cbeb07f5741a4b7012a079f897c2fd8a225486ce16a7988280e
MD5 1ea0c9729c944904a6eb53b7f21707d6
BLAKE2b-256 1bca5629087804e96903602daad62d1c608c5ac44c61682e33f9ddae2f2ab86c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c32a10b797e6b422f9b650c77ed1760b78bdd9f8503ff98c65e233214070990d
MD5 a9c1d07afbeb0aef886bdd1b61167a2f
BLAKE2b-256 cb9862dde34a02abe46d353908d58ce84f38ac7b6ad8995443ff9f0c14f0dc90

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