Skip to content
项目

关于

Polars 的地理空间扩展。

科学与工程

这些数字如何统计

实测星标增长

24小时
+1
7天
+3
15天
+7
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

GeoPolars logo

Documentation: Python | User guide

GeoPolars: geospatial data types and operations for Polars

GeoPolars adds first-class geospatial data types to Polars. On top of being compatible with many existing Polars functionality, these data types also come with a suite of geo-specific expressions. They are regular Polars expressions, so they work in lazy queries and the streaming engine like any other.

  • Native geometry types: points, line strings, polygons and their multi forms, in 2D, with z and with m, stored as GeoArrow.
  • Checked at plan time: a mismatched type or an unsupported operation is refused while the query is built, not halfway through running it.
  • CRS-aware: every geometry column carries its CRS. Reprojection is backed by PROJ, and area and distance are measured on their ellipsoid for longitude/latitude.
  • GeoParquet: read and write it with Polars' own Parquet readers and writers.

To learn more, read the user guide.

GeoPolars in action

Reading GeoParquet

GeoParquet keeps the encoding and the CRS of its geometry columns in the metadata of the file, which Polars reads when POLARS_GEOPARQUET_READ is set. The CRS here is longitude/latitude, so area measures on the ellipsoid, in square metres:

import os

import polars as pl

import geopolars as gpl
from geopolars import MultiPolygonXY, geo

# Polars' GeoParquet support is still experimental, and must be switched on.
os.environ["POLARS_GEOPARQUET_READ"] = "1"

countries = (
    pl.scan_parquet("countries.parquet")
    .select("name", geometry=geo.from_wkb("geometry", MultiPolygonXY))
    .with_columns(area_km2=geo.area("geometry") / 1e6)
    .sort("area_km2", descending=True)
    .collect()
)

From longitude/latitude to GeoParquet

Build points from plain coordinate columns, reproject them, and write a file that other GeoParquet readers (such as GeoPandas and GDAL) understand. POLARS_GEOPARQUET_WRITE makes Polars write the metadata they need:

os.environ["POLARS_GEOPARQUET_WRITE"] = "1.1"

cities = pl.scan_csv("cities.csv").select(
    "city",
    # EPSG:28992 is the Dutch national grid, in metres.
    geometry=geo.to_crs(geo.point("lon", "lat", crs="EPSG:4326"), "EPSG:28992"),
)
# GeoParquet needs the CRS as PROJJSON, rather than as a code.
cities.with_columns(geo.crs_to_projjson("geometry")).sink_parquet("cities.parquet")

Every operation is also in the .geo namespace: gpl.col("geometry").geo.area() is the same as geo.area("geometry").

Installation

Install the latest GeoPolars version with:

pip install geopolars

GeoPolars is in alpha: expect breaking changes between releases. See installation in the user guide for what it requires and comes with.

Compile GeoPolars from source

GeoPolars builds against a pinned commit of Polars, which make install checks out into .polars and builds as well.

  1. Install the latest Rust compiler and uv.
  2. Install what the bundled PROJ and GEOS are built with:
    • a C++ compiler and CMake, for both.
    • SQLite, both the library and the sqlite3 binary, for PROJ only. On Debian or Ubuntu: sudo apt-get install build-essential cmake sqlite3 libsqlite3-dev.
  3. From the root of the repository, choose one of the following:
    • make install, an unoptimised build, with fast compile times.
    • make install-release, an optimised build, with long compile times.

Both set up a virtual environment in .venv with GeoPolars installed. Run make help to see the other targets.

Contributing

Want to contribute? Read our contributing guide and check the issue tracker.

License

GeoPolars is licensed under the MIT License (SPDX: MIT).

探索相关项目

加载中…