Skip to main content

entityraster

Raster-valued attributes for GeoPandas: one raster per row, with explicit zero-vs-unknown semantics.

Documentation · Getting started · API reference · Changelog

Many analyses attach a raster to an entity: a person's activity space, a patient's exposure surface, a site's viability map, a parcel's time series. Usually these live as a file-path column plus hand-written loops (open, read, align, accumulate, merge back), and the loops are where silent errors live: stacking rasters with different origins, treating outside-extent cells as zero or as nodata without noticing, mismatched resolutions or CRS.

entityraster makes the raster a column. A GeoRasterFrame is an ordinary (Geo)DataFrame in which one column has the pandas dtype raster: one lazy reference per row to a GeoTIFF/COG, with its header metadata cached. Pixels stay in the files and are read only for the rows an operation touches. Filtering, groupby, merge, concat, sort_values, to_crs, sjoin and dissolve work unchanged, and the table saves to GeoParquet with its references.

gdf["area"] = gdf["activity_space"].raster.area(threshold=0.5, relative=True)   # one value per row
old = gdf[gdf["age"] > 60]                                                      # rasters follow the filter
surfaces = old.groupby("gender")["activity_space"].agg(er.mean_surface(outside="zero"))

Status: alpha. entityraster is a research prototype from Urban GeoInformatics, evaluated on synthetic data; a software paper is in preparation. The API may still change.

Installation

pip install entityraster
pip install "entityraster[explore]"      # + folium / mapclassify for GeoDataFrame.explore()

Requires Python 3.11 or newer. Tested on Python 3.11–3.13 (Linux, macOS, Windows) and against the oldest supported versions of the dependencies (pandas 2.0, GeoPandas 1.0, shapely 2.0, rasterio 1.3, numpy 1.26).

Quick example

import entityraster as er
from entityraster import synth

data = synth.make_dataset("data", n=1000, seed=42)   # a synthetic city; for your own files see er.embed below
gdf = data.people                                     # GeoDataFrame with an `activity_space` raster column

gdf["area"] = gdf["activity_space"].raster.area(threshold=0.5, relative=True)   # one value per person -> a column
old = gdf[gdf["age"] > 60]                                                      # rasters follow the filter
cube = old.rst.surface("activity_space", by="gender", outside="unknown")        # mean surface per group (xarray)
cube.sel(gender="female").plot()

Attach your own rasters by key, never by position:

gdf = er.embed(people, catalogue, on="person_id", path_col="file")             # join a catalogue of files
gdf = er.embed(people, template="rasters/p{person_id:05d}.tif")                 # or a file-name template

Five things to know

  1. Attach rasters: er.embed(table, rasters, on=…, pattern=… | template=…, column=…, index=…, geometry=…). Everything else has a safe default; problems (missing files, duplicate keys, orphan rasters) are reported, never silent.
  2. One entity: gdf.loc[uid, "col"] is that entity's raster: .mean(), .area(), .plot(), .values(), .to_xarray(). A missing raster is a missing value like any other (.mean() is nan, pd.isna(...) is True).
  3. Every entity: gdf["col"].raster.mean() / .area() / .exposure(layer, outside=…) / .composition(landuse, outside=…) return a Series or DataFrame aligned to the table's index.
  4. Across entities: gdf.rst.surface("col", by="group", outside=…), stack, overlap. Here you must say what cells outside an entity's raster mean (see below).
  5. Pixels are lazy: the table stores references, so the files must stay where they were when the table was built. er.to_geoparquet / er.read_geoparquet save and restore the table; er.to_geotiff exports any surface for QGIS/ArcGIS.

Zero or unknown?

Every cross-entity operation requires outside="zero" or outside="unknown" (alias "nodata"); leaving it out raises TypeError, because the choice changes the numbers.

outside="zero" outside="unknown"
cells outside an entity's raster (or nodata) known to be 0: never there unobserved: unknown
mean surface divides by all entities divides by entities that observed the cell; NaN where nobody did
exposure(env) missing env cells count as 0 dropped from numerator and denominator
overlap non-intersecting pairs are exactly 0 non-intersecting pairs are NaN

Rasters with different CRS, resolution or grid origin are an error that names the offending rows, unless you opt in with reproject=True, resampling=... or snap=True. See Concepts and Defaults.

When to use something else

entityraster is built for one raster per entity, with different extents, kept with the entity's attributes. For one shared raster over many polygons, use rasterstats or exactextract; for regular aligned cubes, xarray/rioxarray; for SQL-engine scale, SedonaDB, Apache Sedona or PostGIS raster. (It is unrelated to the Spark-based LocationTech RasterFrames.) See How it compares for a measured comparison with rasterio loops and xarray.

Limitations

  • Evaluated on synthetic data; not yet benchmarked on large real collections.
  • North-up, unrotated GeoTIFFs only; one band per reference.
  • Single process: no parallelism or out-of-core scheduling. stack materializes n_entities × grid; surfaces stream.
  • References store absolute paths; moving the files breaks them.
  • zero and unknown are two bookends; partial or probabilistic observability is not modelled.
  • Plain gpd.read_parquet returns the raster column as dicts; use er.read_geoparquet to restore it.

Development

git clone https://github.com/Urban-GeoInformatics/entityraster
cd entityraster
uv sync && uv run pytest
uv run python experiments/run_all.py     # regenerate the experiments of the paper

See CONTRIBUTING.md.

Citing and license

If you use entityraster in research, please cite it; see Citing or CITATION.cff. BSD-3-Clause licensed.

Metadata

Release files for entityraster 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for entityraster 0.1.0
File Size Uploaded Provenance Actions
entityraster-0.1.0.tar.gz 67.6 kB Without provenance Details for entityraster-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for entityraster 0.1.0
File Interpreter ABI Platform Actions
entityraster-0.1.0-py3-none-any.whl Python 3 none any Details for entityraster-0.1.0-py3-none-any.whl

Total release size: 115.6 kB

Release files / entityraster-0.1.0.tar.gz

Download URL entityraster-0.1.0.tar.gz
Size 67.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ed04209bb328afe03f6042b9a758d4800cd524ca86e8f770a9d7e628571f5fcd
BLAKE2b-256 checksum
How to use checksums
4421288ce722bb8019204bb48b3dfe8bc31828cddbb34b538e9c95c0edc5f04d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / entityraster-0.1.0-py3-none-any.whl

Download URL entityraster-0.1.0-py3-none-any.whl
Size 48.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08f59af9caa1eae21e88234e8b47255e78f7928475f2c5573473e1b751c223f8
BLAKE2b-256 checksum
How to use checksums
c12b4e1e172e8f86ee7b31e93931ad512de9edce10eb048c8711cb8a4e81d751
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Security for entityraster 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page