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.0a13.tar.gz (173.5 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.0a13-cp38-abi3-musllinux_1_2_x86_64.whl (10.9 MB view details)

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

polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_i686.whl (11.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_armv7l.whl (9.9 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_aarch64.whl (9.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.9 MB view details)

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

polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (12.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (9.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a13-cp38-abi3-macosx_11_0_arm64.whl (11.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_st-0.1.0a13-cp38-abi3-macosx_10_12_x86_64.whl (12.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.0a13.tar.gz
Algorithm Hash digest
SHA256 ae539f836ca533afdf4fdd3a171623389535bf66d022f3bd0aa4310f94e8590d
MD5 cd0c25a6bf2b00dcd06ae4131b96975a
BLAKE2b-256 4b1cd901fa7356f21258e04d13980993be5fdb5676c492e91bf3ba11307d14ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ff3b096cc33f5994bd52fdcad6d224f84cc8d97ef2650f9ffe277459fe9a6f25
MD5 02f3c895af537cf4068e2d5f4247a2d4
BLAKE2b-256 09a17c78a5c14fefca35f4f09c56c326ee2e0336a57262b6b2f73a55ba899225

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 19e21843a8a5ecba001bffbea0913221da2c4b027dcebfb7ac46dd2c61ed0744
MD5 54c269cfacd9cecb30f24b317d36b083
BLAKE2b-256 87b88b4dc954c5e9c68461f31a44a76f70158a8c8aae0123083a13f80e79e304

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 07ef1a0bf12eab6db2e339b53c5e737ddf937c1a9174c11fb1a8eb2b44c4a1a0
MD5 abd29161325daad8fe2904bbadb427e3
BLAKE2b-256 e58982e60376e3971acf66d688f16962380e1bb0a7960d2773eb4216f6248d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 05ed739a6c2a1238c4aa569454ac37f3ecde5ab1462ec9267095ffe5318834dd
MD5 652a68fb5950ac673dba2de617073747
BLAKE2b-256 ca275fff8691934f2855f90f1eb3e7a5b8c9b91b3dab965a0ac84d7f8ed08486

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b2612259da6c3b8cfd23aa115b18659b2e92f69e69b3b073da06ddc1a50842e
MD5 1d6bdc82dc90f463263d601dc14a543b
BLAKE2b-256 57ac2712694a34a75b909febcc552116a58f51a38e8ebd21f399e89cdad9bf8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a2bbf532684174952215cc56fc8a7f36eb2a549ed1613e590f706ef27d28be1a
MD5 312fb5ad51c90e497bebf20da79558b7
BLAKE2b-256 9428c79fd2d674b04ef200c0955931f0971c0b16bdbd82be89273ccca653f476

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d26d52c4b4157c3932b73630b86e76784fb7c04474387510950aa9cd636dfc4d
MD5 86817e1f05cbbb4d5e09f8a6f0ff25dc
BLAKE2b-256 b0601be56f15239d8b5c771404a00e716e5f46ba2ed236a839253fd02b392044

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 02108bc03f5300eadb148e4a37ddc93f26ac4cdbc8a3da39a28dc948ddcd76e5
MD5 5cd3a7a4cbebbb89fc1ccc41da23993c
BLAKE2b-256 66500e82d08ad9cbc5447ab855c89f088e635e7ff9478b14b9de69b718cacf06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a8f2406e8a8d4117e8fee51184f1fe5f6213884b29217b9fe4f05b2ddfc2ac0
MD5 76213030fb60b8b494d31af3daac6502
BLAKE2b-256 e444a8412e4a2b120675913b87e2e0d225c5ad40d17d3a41a0e01d187a229f25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a13-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ff92d0c6ccaf362e5a0e4f328569bf294d52b13b133de36bb94ed9354f91837f
MD5 79f78fc3a0903089b6e5d2a629fda2c6
BLAKE2b-256 b3b140dd8a66ac285c8d13f1d67dd2576903c1526dd1f132287f74b555c4d113

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