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.0a18.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.0a18-cp39-abi3-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.1.0a18-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB view details)

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

polars_st-0.1.0a18-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a18-cp39-abi3-macosx_11_0_arm64.whl (5.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.1.0a18-cp39-abi3-macosx_10_12_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: polars_st-0.1.0a18.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.0a18.tar.gz
Algorithm Hash digest
SHA256 da5fe04c4ce75de37d615147eac3ba02dafd3c4800080a134f7cde778dfbf066
MD5 0880d5d3f43034eab5956ec5552bf5f8
BLAKE2b-256 94e38a8c9eff6740cb74a4f414bed6e61fd6e7de068842c2b8a2fc2ecca8f0a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a18-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 46ed6b90f50716c83f5944b5ef84017556fe1111d5d4bdbba7c318a84538b190
MD5 4032940ab2c6ae18048f7836a4662c13
BLAKE2b-256 7b61287ae15c4bdeabe6ae47a51e132ab1f8dfe6412e60c755e6daa58fc2c4b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a18-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fd25179a4f9ffbaa927c31df43adb59d15125a64fea7800af1ad5ebaaafcddb
MD5 4fe22ce84ef9594025bb077f55e152e9
BLAKE2b-256 d2a15cf142582c733847ef45b2f4ffc2187dd74241b5f7fbd5c056a38be0c987

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a18-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 31a382ca028495c4e402ba88ca2d249870d74a9d8c22e171813f449fd34a0573
MD5 6328ef2c5a2bfbb28663cd4bb01d6c1a
BLAKE2b-256 90b3838cfc81259de53e31eda850a9c53a02881bc582611d980077ccf0254cc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a18-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 73047707879e1ce8c8ec6d74fef2d0800e91a14fadfb3756d1074190181e7a35
MD5 584640a151d73b04cb817d47a34ec7e7
BLAKE2b-256 3722a929372230514c246dd0b6b2d06f2aaa5f485b9c72b8583e85534b24bec6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a18-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b6a1ad009188f0bc5842a052dc7733ef9ac31dd519c8d28fc472ac8a8b66603e
MD5 461ffbe786bd426b311a235886292492
BLAKE2b-256 45e29762072e7ccf1a0b84847a8f37c6301455d0f06b2a4a5fedf6c80c7bb8f3

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