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.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 incredibly promising tool for manipulating geographic data in Polars based on GeoArrow that likely will outperform this library's performance by a long shot. 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.

Storing geometry as EWKB and delegating core functionality to GEOS allows polars-st to be ready now, and provide additional features such as XYZM coordinates, curved geometry types and per-geometry CRS information.

I really hope Geopolars get there soon, and that maybe some of the API design explorations made here will have helped make it even more pleasant to use.

About Polars

This project is not affiliated with Polars. The design language was made very close to that of Polars because I found it amazingly appealing and liked the challenge of adding geographic meaning to it, and to also highlight the fact that this project is an exclusive extension to Polars.

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.0a14.tar.gz (177.6 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.0a14-cp38-abi3-win_amd64.whl (6.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_st-0.1.0a14-cp38-abi3-win32.whl (5.4 MB view details)

Uploaded CPython 3.8+Windows x86

polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_i686.whl (6.5 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_armv7l.whl (5.3 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

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

polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a14-cp38-abi3-macosx_11_0_arm64.whl (5.8 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_st-0.1.0a14-cp38-abi3-macosx_10_12_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.0a14.tar.gz
Algorithm Hash digest
SHA256 2856de10bbdc299edcc80b2ff6fab03e042084c1ae4c0c41577617d81c56b55d
MD5 34494c18a28b03e4351051c86fbe8da5
BLAKE2b-256 da49bf798def06de2333cededdc83d5be3d23ff4090a65ae6dd0db00443b9055

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eb50cb9b77503d4c4e10bd4150a35a169426a1106c035ec095dd3cbabde20273
MD5 3fb6155ef8eb39177251b71e1f287b4d
BLAKE2b-256 ca156310470ba9e633dba328c988e4b9649ad5431767e969905fe0841e7293b5

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-win32.whl.

File metadata

  • Download URL: polars_st-0.1.0a14-cp38-abi3-win32.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 d69627e664af9eaace43cb6be81ce0c5c441657c65263019bf61359105c53504
MD5 335c3dc6a48943a36853f53a6d9ccc3a
BLAKE2b-256 186a6257e7f033f4f0fd1dbbfc20d9bccc4881b20178af9081b3500367ce06ef

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ef448f22020299cf281ee46e2982b5cef6509676a7918516ed1042615b13fed8
MD5 8425d74c883db9b1a0a8edef452e494b
BLAKE2b-256 d3e85e66a811bf1013b8ca1c7fc2c73603117f4ea57f16144d8aefd86da1d6f0

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 a8638999a5fd8b22d937126de39bfe93c33d2f68b7bfd59bae2f11be297d90ed
MD5 9cb19da877f7f58cc90c213e20ed5c39
BLAKE2b-256 4bccc47a9ce36d0110201a9c0fae64283e64a51a9a7fe7ee1211bc0012c0a384

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 1200befb8e559911af82727647bbd86a8690da100db8f0c108598bde7fd12fed
MD5 f2c4de7fdea7a11e290ddae00db557d4
BLAKE2b-256 a86cb25a058e51535bdbb6727ef6b9f5bd8d5846fbfd2e58390407f6c9afd079

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bc43e6698a610bef8451b9e9f7468ed73e42c1480cb83e4c0cebf944386bb607
MD5 6045bdbe58a1e0d55c84ea87afbed144
BLAKE2b-256 95cf8f144dfaa26e304a24eccbdce5e0d2b92673409b73bb19aa42b4abba875b

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9a111e3620445130febbe3d25ed623c5090dfbae9eae1df5fe0d3457e68f1b0
MD5 d46ddc70ff6e4b1b265f7b6b290f686c
BLAKE2b-256 dd6db71c15ce11bb8f172366db72c1954705d72428272eaeef21fe82d3977f0f

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6c564b4c72c6c7acaa7ea4f5df1d44a67fdb0e4981cc37a0edea8f032817d39a
MD5 40c4d797cae3700f6c70e7ffede8949a
BLAKE2b-256 19291d333e0b0bf8966bb149d5c7028a15002561440bbc410038dd490fa0baab

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a08a83d6bc67a1eb0e215e048fb6e0a68bf281aebe015609a423f8d9ff3c8e3b
MD5 3cd5a8d6584f612a17c20edb16efb78d
BLAKE2b-256 4b7f7327b2270d685dead8ada31cf25a1d8511f0b2043a356e9b9ee1106475fe

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 041940d9936c5f1f4d458ec8af694c1c48323e04d6a8e513afe0f0b460c64694
MD5 2211fa5256fad6744bf8159370616be3
BLAKE2b-256 16c93356260baecf778ced7eaa19252b87dea39bfb8eedb891e12b4e8ff589b3

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f0f77c6491f1fa804dd46adaf1017006cc379255fe3ebe2acaa4a8ad7af09c28
MD5 72506a3515591235644efde24447e352
BLAKE2b-256 0eecb970c560d0943068213bb674b05910a7ff5de7448458fe5367d76b84b4eb

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a14-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a14-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8765126b9da0716b8e57bb69cc0cb78cb665cae4ba04bf019435a9aed9cce8b8
MD5 e508c68421f6a06c2654ba372df91ada
BLAKE2b-256 3d60f787af0e5927a5d301681ab9725cfbb2cf08495a093703b1e96fbb1765b2

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