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.1.6.tar.gz (197.3 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.6-cp39-abi3-win_amd64.whl (6.7 MB view details)

Uploaded CPython 3.9+Windows x86-64

polars_st-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.7 MB view details)

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

polars_st-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_st-0.1.6-cp39-abi3-macosx_11_0_arm64.whl (6.4 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

polars_st-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a2db2b6fca303887b090d5a2d7443cdca8e96b79518ea01294c6b9b560c95fd2
MD5 01d52390307bf8bc7710b85f2e900b30
BLAKE2b-256 d0fdc999b2351bbcf7935c8351db76be423dfc7bef45974a99edf63230b329f8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.6-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 88e0419bbcc831be5f60c2ef60b7316a972751aac7568af39b8d09c7f92d52c0
MD5 f9e14d9a0019b1b55947a656921220aa
BLAKE2b-256 74478b6f9b09269e2a6937c3f1e817a8b5a1d86b5800682151766d6825269c83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f7d1c9ba68e35fd41e9c718d5c639551d6a944206853cf6123db1c3114d0688
MD5 19cfc9c7e9d3ed2aff84ac7e9d7ad50b
BLAKE2b-256 404128838a69fe28d1251eb0b18c60e00d6f9e611d8be7f1511bea683f619237

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3ca50b451a2a30525cb82d29232d9a3827a674abdaa91c1c3d5d575e30b9d211
MD5 e2334ade6d3d52ae12c02ab83935c126
BLAKE2b-256 663feba8c7c06b64cdd921fd72652a55ae0a085af7fe4f3f82978ccd03f23cfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a98218090a97272f602dfba6c5028d07255195d62c4556398a8b722cf046717
MD5 b28d2c76097c84e321db9b8b7ce64b88
BLAKE2b-256 b31ad7d25a56ee9d0aff0f179406a10afd7e0e73eee60831838ba62a38fb98e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3864f0ea4e065f912d1e0ec3a576ebef6a36b975f746721104e2d0470b2a5754
MD5 1d1fe79c9e11f875095c9c22de9c333f
BLAKE2b-256 c77dc40a7ad5ac5987964fc20aa6f8d3afb310da81966d5a2ba58c67984c6edd

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