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

Uploaded CPython 3.9+Windows x86-64

polars_st-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (44.2 MB view details)

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

polars_st-0.6.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (41.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.6.1-cp39-abi3-macosx_11_0_arm64.whl (49.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl (52.6 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.6.1.tar.gz
Algorithm Hash digest
SHA256 f0f080b40c96c0384543602d8377ee82802fef45be2e7d723e45e48f57bdc6c4
MD5 a2a6f70474fb2f634a3828b31ef68505
BLAKE2b-256 45579faba55634cb5d49ae38b1e15e18e460b1fa8e7a79a552265ee2cc066b56

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.6.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7482ebda94420341eab6390993a2470a449930b50e363b63379a9cf1676f3e3b
MD5 4860eb9d5b8d454639752d68977c933b
BLAKE2b-256 f61f1e07b8a4315c89e52bafae6359ab070994b2b93be898e2ccc228c8bfec83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f418b169e95ed1143c4ad9da34c0a73a35d820d7f43ef37e54ff343c322c48b2
MD5 0359e12621e0cadc83d157993f911a25
BLAKE2b-256 4ef5d3faf49bd366f7af0327153e5b1330ffcbe0e20adc5fb55e31367bb24ddd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.6.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e6ff3fa9abfc518f0109727a0f175002538d56b69935d01fd34e590e34d38b1d
MD5 45ae889ad5b5886f37677cade233d97d
BLAKE2b-256 cd621f3dadc339b3870e943070c7b4c4de4e84aa8ef3b05d9b42f9930fd3d8a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.6.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2355dfeeb88567f6eca91c78d2c2c68f1aec66a5a87dab6c1f4b7f576e874b3a
MD5 75b3d9410c86c68d02917b820994ea37
BLAKE2b-256 9df08b37fec9096a26221843c29384fad1e7977ad9e0ac5886a56874ee0d40bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2762c73e7a6fcdac553bd533352f2e63faea4e6a232bb99c126917c8e3252e51
MD5 fe25935a7197f07a6ed5cf2f54ffeadd
BLAKE2b-256 abb8e6b4dd1db3eadad8a70f5372905edda5334204144fc7bc997e18a68ef610

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