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 as pl
>>> import polars_st as st
>>> gdf = st.GeoDataFrame([
...     "POINT (0 0)",
...     "LINESTRING (0 0, 1 1, 2 2)",
...     "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
... ])
>>> gdf.select(st.centroid().st.to_geojson())
┌──────────────────────────────────────────┐
│ geometry                                 │
│ ---                                      │
│ str                                      │
╞══════════════════════════════════════════╡
│ {"type":"Point","coordinates":[0.0,0.0]} │
│ {"type":"Point","coordinates":[1.0,1.0]} │
│ {"type":"Point","coordinates":[0.5,0.5]} │
└──────────────────────────────────────────┘

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.0a11.tar.gz (172.9 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.0a11-cp38-abi3-musllinux_1_2_x86_64.whl (10.9 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_i686.whl (11.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_armv7l.whl (9.9 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_aarch64.whl (9.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.9 MB view details)

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

polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (11.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (9.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

polars_st-0.1.0a11-cp38-abi3-macosx_11_0_arm64.whl (11.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_st-0.1.0a11-cp38-abi3-macosx_10_12_x86_64.whl (12.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_st-0.1.0a11.tar.gz
Algorithm Hash digest
SHA256 aa1dd7a6e3872ae6d5ecbaef67035448041658b6b1898bff256cd0113189e06d
MD5 76308aeadefb6c64ff77600772d70bf6
BLAKE2b-256 ca82e22e29546d6f69dc2f354f0cbd1c720368fffbc734c786aa916abf8c9471

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 16acb86993c4d5fef2bc6741a2bfdb2c5aba08bcddf825f6c6800ca6ce01dfc3
MD5 816d01929a0ceddc4b7193a117f34951
BLAKE2b-256 2f48e4cc7b679d570176837a0c8db0e08c32f58357fae75c48455eb35d8bbc86

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 010116465a97f38dd0e927055153ab11630fcdc2600707a2408ec8d314d4b25a
MD5 d6106ee13781a1c712f5479f94aa8941
BLAKE2b-256 1cccba30cec49c5e4e08de3ab9b01643fc8f5c6b1e1d6e1b243a8df623bb5444

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 2b2661035de1414cc48b7cb959f575557a59a0282626a7edf4a43ccb96e47687
MD5 1de741a11ba25aef0f02e6269e0bbbd5
BLAKE2b-256 a9e18bab014e66c5b517eae6867c8cc0dd2e9b0392ee323a5251a9693878a2cc

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 526e07cf272c66e64688dbae34bc8b8fab39a3410affd715e5db93ed18710cd4
MD5 e35946fff2d395e86f86265b78bd94e4
BLAKE2b-256 75ed5604d590eb0db52bb8d542469ecef4f8abd84d1ee259e54ac48601d6dc18

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6684f72ada6f1dea9fac7365c2122b8ad01a33da185a5a26c53b1daa109ae770
MD5 6d6f2e9ffab0163f60fc5f4ccf605477
BLAKE2b-256 2a0f3fdb91bfa5f21bd5088bb40f346c6394fcea311866868b8fefcaeea2412e

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d3e4f88276c5f3bdf8a603e2d8672c0c2d1569226b44f0298cd93bc89d641fdd
MD5 9607eeda55b8f37909276fe92d68679a
BLAKE2b-256 ee02ae5230262e88afc24c5dae111acc5a52e2c360ae83d62941ed614804cd46

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 05932eaa3166688c28ce5e7f927a6d3ac543adb1699bc34485df0335497617cd
MD5 4e99c225f6461da2b4859531f09ef5ef
BLAKE2b-256 f7c8e6f8651490d276928ecc1ad3d5d5e1d7da1dac6d7c34edbe4306a015dcb9

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7620b69d837676b998c395214c2cce910b599bb9b3395e442fd69594f10764f4
MD5 e3d555b3b5fe811526d55365d4731fab
BLAKE2b-256 6e7f1a50ac5dffcdc00a24b7bd2f1f638fa323834bc8da51a5719d3490bb4fd4

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3282b922c9a32f502c2e2cf45ad9950b483606dc87c6a594345660729ab22243
MD5 c3cd7fe58960e164a77da5ae2059db32
BLAKE2b-256 03be1b340c2f9785eecf2ab2d0eb3fd026025011ceee7be1d5e23fc781bd6aa2

See more details on using hashes here.

File details

Details for the file polars_st-0.1.0a11-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_st-0.1.0a11-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4b3293b566975261de9eec23c8ce3a4cc7741e7901c35f305c1d16d1996b34b2
MD5 87181fe0e0dc703b77631542eecb6c54
BLAKE2b-256 dada9c484f0d0bcb5c083fb364779a3614d57ede9112c83482028ddbe1f889c9

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