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.3.tar.gz (244.0 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.3-cp39-abi3-win_amd64.whl (46.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.4.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.3 MB view details)

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

polars_st-0.4.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (39.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.4.3-cp39-abi3-macosx_11_0_arm64.whl (46.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.4.3-cp39-abi3-macosx_10_12_x86_64.whl (48.4 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.4.3.tar.gz
Algorithm Hash digest
SHA256 7d4c1cbc53a1e1cc947111614f4ff5d463d73acc11cf276408fec59798e940d3
MD5 5365bf18275681505c4a8ec4355373d9
BLAKE2b-256 0e334e287d0f26a8181c2a1393d6d34f3b823e9b5952e5c04367dc5f1187f427

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.4.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c20af615a7cb0483cd0d482ea921e26a3a3512162e52cd5cee19404e97874cf6
MD5 ff66eac3c1b6a8f157575e70b0dd638e
BLAKE2b-256 365c4e2259d1a0a6142829b73e129ed9b9b3fedbaa9de6f13836e7c4706f1c09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4e6a0ed8b5ff23fd9d8b0af682935a294fea38ef5bc1ea123648845c97bc0b9
MD5 3d6607d91f6c90f4ff7c8a808e84942b
BLAKE2b-256 3b1a844ab71783f6dbd358f6881daa2037889695277facfe54abfae51a636362

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4436b49e2a30a6cb26831623e56f407a014e33630c5bc29db29f6397285b3907
MD5 6c8ed55476a9c499d6af4b138c050b5c
BLAKE2b-256 aabb05a54f0d66051d1bbc4a5b5fafd288654a46a6b28731e2df5eb00a0c46ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca599f943e07d6cc12f7a1a57a426e8735386c62db24535edec9901071841512
MD5 6d53bf5c2b5cc1f4e27f94deaad4cec6
BLAKE2b-256 adadcf342508bbc49dcecf98e841cc54cd1deb1faae148ad7c96a106b0d16734

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.4.3-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 06bfbeb6958196e742b5ddfa6da605948525d2f5e8b5b23929a3ebe8769c1e95
MD5 80566e757ced604fe34a5c30dc52c573
BLAKE2b-256 684fc769d0b23c95f4c353c208b0b4962db9ecfd24bd17b40824c6a807976466

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