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

Uploaded CPython 3.8+Windows x86-64

polars_st-0.1.0a15-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.0a15-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.0a15-cp38-abi3-macosx_11_0_arm64.whl (5.8 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_st-0.1.0a15-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.0a15.tar.gz.

File metadata

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

File hashes

Hashes for polars_st-0.1.0a15.tar.gz
Algorithm Hash digest
SHA256 7c5fe1e703cc072dd046a7550d6618bbad0fb7acc489aad97e8ebcf112e7d7c7
MD5 e430d5c18c8de841eaeb341ed127ecaa
BLAKE2b-256 95f55cc48ca6a77410a8e4b7b203b0d4fdd99337c64a8a8dadfcfbbed1b22a32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a15-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4f2f85485d3884cc108049c54b6cdd9e89980b8bee85a8db7eaafeebf198ab84
MD5 9ad65e39574ee02e010b2c0ab916aaec
BLAKE2b-256 9a1de9865b79ac445c106273f02f3e9b6396d44df9344a56a269c0df555dd7b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a15-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84355bde2f0a5e045bea2b91a1e453ec804860141d649f4757cca819ccafbdeb
MD5 0a2e47a3e2128f840f7f232a66802387
BLAKE2b-256 d342b28814407a394adf3c9e3aa8c898321ccb7be3938af4d3d5103a19b67838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a15-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f3a84ea67331a7b6bfa5ed5c5ee9bc51c3d37fac904f5e981836d768ce1a35f
MD5 2484f051f54d5b06ce846584b2d8c31e
BLAKE2b-256 bd46ac6b22658222b6e0d7e119939cb21fd262a1a0fe9af06a02f8fd2c75a3d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a15-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9d5204813439676361557a3ad7624530625231e9fce9a704bcc7be7102f5c94
MD5 e47d17d82d024eb5064684d8ae42a4d2
BLAKE2b-256 9b0a8e32dd847d2bc4a1c2fdff4390413c7019553dce4f59f84c4265af4bd208

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a15-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 072161016f3529b4b70f2e214a94af4e29c91f781e222baeffdb5421b2f57926
MD5 2a90b81c74e18c967df778d5ed40c8c6
BLAKE2b-256 d17c9189603a9bd8b140998bd62ee3f72cea76749df954c57aa4f2fc60e34c44

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