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.0a12.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.0a12-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.0a12-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.0a12-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.0a12-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.0a12-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.0a12-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.0a12-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.0a12-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.0a12-cp38-abi3-macosx_11_0_arm64.whl (11.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_st-0.1.0a12-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.0a12.tar.gz.

File metadata

  • Download URL: polars_st-0.1.0a12.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.0a12.tar.gz
Algorithm Hash digest
SHA256 6b25462d6a2a2ae125aa5a2fee0a436d3c7ac8913e8131b8ef72969c1a0969fb
MD5 2f6961d430bad208e0ef389a1377c7c0
BLAKE2b-256 0371f4bbefa7f603dde68a695875821d736d2dd992eed2e3aa484059b68150fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 20efda41ea79c24fa4019157a74858676486b6789a2b3697e10f26b5f2e80481
MD5 ea6740af4ccb11096b9948a63e56c4ec
BLAKE2b-256 26bcf2230bdab74f1841ba3d7fa62fe4285b83a110fa27553ac05fee87e3422e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 b171eff428f214de0e14a00c0508f62c9ad390b6467e6f94d8abc7e8e43263ca
MD5 1f16bc53357ff4f3455bbb65f00e1df0
BLAKE2b-256 d4eb75fa4b410da0dd05f12047e5be19a78c78cbff56827b52a346e7aa938d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 0804d48e8e59be9b263415800209575d539b1b6a78abc302f5ee5928da30d681
MD5 3c6c5cde7b52c98e9f3da44352fba7c5
BLAKE2b-256 0457f8ffd4b655713c8b0504e0742ca479e49dceab98e7ad728a909f9ad750c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 01a7115e04461a2fd0738a0e9378ce0fed4ccc8bb19d1131b400c7ebf059a625
MD5 b1aa52aeb27114c8701153379a89b032
BLAKE2b-256 cadb29ce657751374fb3deec0fa14060dab8bb6bef264040d1c6ec5124668c38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ade68951df631e24eb729f44f1c25bc6f00c3ff0512af40e9c81b02c98a72d9f
MD5 5f7d45b63a1e67c29ee07d9c2a48f3e2
BLAKE2b-256 6b78e367b264a20cdcbeda9f660f583d2a57e83b8626e8004f5751ffe6a619e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cb785b8461b6332d7dffa0d98e93bce102120a11f65608bb0c7b89fa95cd3802
MD5 eb0961627a5ae2abcadcb8e54f165fe9
BLAKE2b-256 fef1aabde224b9983aa705773fcea71da8917590c370551aefeea75acd413031

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a7fe8ecd95e6bb2fceb91a10ada678a174f896ae5801142468369c40e7f12d2c
MD5 80ef3663d9b081ab495853a6d217f243
BLAKE2b-256 36db96c3b2338f09c68b6e63041d8fa1aed8a2fb304a944eb98680c9b769b2eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc72dee33ab259a49f376c031a717575c2649aa90533af96f2fe12574cdab935
MD5 e6d1cb65b28bceebb9a84f6976541b60
BLAKE2b-256 e54c2953d886fcf54db734d60c2418bb3ab91cc15b42d79f4fa15e6a9e79db47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5f5de3b192f916634c8983685bfaeeceef27b5aa58b97ef90d619be82067ba8
MD5 7b5ad63184d51dc2a2b73e477b0b19c3
BLAKE2b-256 b56a23bc1db26c29948f28ce24f49830796dc0d3963ba8ab802ff0df23e8d027

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_st-0.1.0a12-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 88212bda9b6e984649cc140c4eb70d32814cc8a5232ffd814f9ab7c29355b59e
MD5 3ff5224b204419a7193e4af1dbe61e75
BLAKE2b-256 fdff814e698243947e54651bd81d3d6cb2ccd904f8be641591bbe1b21ffbf0d5

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