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 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 very promising tool for manipulating geographic data in Polars based on GeoArrow that likely will outperform this library's performance. 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 3D / 4D coordinates, curved geometry types (CircularString, CurvePolygon, ...) and per-geometry CRS information.

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 project is an exclusive extension to Polars, and as a tribute to its effectiveness.

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.0a24.tar.gz (178.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.0a24-cp39-abi3-win_amd64.whl (6.1 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.1.0a24-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

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

polars_st-0.1.0a24-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a24-cp39-abi3-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.1.0a24-cp39-abi3-macosx_10_12_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.0a24.tar.gz
Algorithm Hash digest
SHA256 3e93d820ef73b9fbfbb73c24ae83aeddc48eaa0aedb218d75faefb17abf0b083
MD5 01425612f5b82ea98a1b426eed05172f
BLAKE2b-256 654ad2831f1f15963f8cb92f2fb63a76b25cf4460de68562372d7fdeb36bbb6d

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a24-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a24-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 17c301e35ed08daf7bf9e4ef7aaf6fe09bdb9b7f9fef200794b7236c7d6d8cc4
MD5 984a473112a75d9b9eddef431b090648
BLAKE2b-256 036a2291ad2def0551f9a5fe00fd70e7d090e7bfebedc8c33cf7821c23d99867

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a24-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e21bf720aeee2dd6a0eeba234a39406809962dc73dc50d28364d909d5bcb43d3
MD5 f90a44cd24788a26a9402ef296de0279
BLAKE2b-256 89c216b3b5960cca19ea46cfeebb28817e6ed6f1514d81a80988d3498874dc93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a24-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ca9811fec939769c7d6161a4b570abd264d2f9fa9ca0b018e2b7f644a13eac52
MD5 d959ca2213b53496029f5e1239a1fab2
BLAKE2b-256 e40c3c2355997dad34fd219209874cbb624e480841a84ad03973e21660e69335

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a24-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a24-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ce5a323ba0f35e070b4b7be4b7d3fd0fab07b13150437eac9c46efd9b265402
MD5 a678563d35d9d86a4514ed0a837e504f
BLAKE2b-256 898985760190366b8d39ad77b82dad70d4ad5fed4c1bba4a7787641d1db5f6fa

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a24-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a24-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3386e4502545a0b6b6b4565f797e587bfdeecf418c3171da300bb1d27fa04654
MD5 bd3e43dec0ca518ccea8076171d0d211
BLAKE2b-256 b734bcd858ce6fca15f9545223dff2c8a2bed4fba8b86a02c91593522158198a

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