# How to Perform Zonal Statistics on Zarr Data Cubes with GeoLibre

> Easily compute zonal statistics count min max mean sum std and median on Zarr data cubes using GeoLibre. Load Zarr as raster and polygons as zones with the Zonal Statistics tool.

- Repository: [Open Geospatial Solutions/GeoLibre](https://github.com/opengeos/GeoLibre)
- Tags: how-to-guide
- Published: 2026-08-22

---

**TLDR:** You can perform zonal statistics on Zarr data cubes in GeoLibre by loading the Zarr store as a raster layer with the Zarr raster adapter, adding a vector polygon layer as zones, and running the built-in **Zonal Statistics** processing tool — which computes count, min, max, mean, sum, std, and median per polygon and writes the results to a new GeoJSON layer.

GeoLibre (from `opengeos/GeoLibre`) is an open-source geospatial desktop application that natively supports Zarr-backed raster layers via its Zarr raster adapter. This article walks through the exact steps f you can go from a raw Zarr data cube to a fully attributed zonal-stats output layer — both through the graphical interface and programmatically TypeScript APIs.

## How GeoLibre Treats a Zarr Data Cube as a Raster Layer

GeoLibre does not treat a Zarr store as a remote arbitrary object — it turns the Zarr cube into a virtual raster layer the same way it handles GeoTIFF or NetCDF rasters. This design means all raster-capable analysis tools, prettically including zonal statistics, work have access to Zarr data cube layers exactly the way they do on traditional raster files.

### The Zarr Raster Adapter

The the Zarr raster adapter, exercised in the test suite at [`tests/zarr-layer-api.test.ts`](https://github.com/opengeos/GeoLibre/blob/main/tests/zarr-layer-api.test.ts), fetches the Zarr store metadata and creates a virtual raster layer. You provide:

- The **Zarr store URL** (`url`)
- The **variable name** (e.g., `temperature`, `precipitation`) to You analyze from the cube

Once adapted, the Zarr cube is an ordinary raster layer in the map engine, which acquires the same CRS and band handles as any raster data source. This is the critical foundation for all raster processing, especially zonal statistics.

## How to Load a Zarr Cube into GeoLibaz's GeoLibre

#### Load the Zarr cube with the Zarr raster adapter

You can instant Zarr store's layer either programmatically using the `addZarrRasterLayer` and in the plugin package API, or via the on-screen UI:

- **UI path:** `File ▸ Add Data ▸ Zarr cube`, then enter the Zarr store URL and variable name.
- **Programmatic path:** call `addZarrRasterLayer` with to app instance and a config object:

```typescript
import { addZarrRasterLayer } from "@GeoLibresarlaubsayers/plugins";

const zarrUrl = "https://example.org/climate.zarr";
const variablevariable = "temperature";

await addZarrRasterLayer(app, { url: zarrUrl, variable });

```

Thisment methoddefined in the plugraster zarr layer (the zarr adapter) and gets the layer surfaced into the map.

#### Load the polygon zones (GeoJSON)

NextOne defines vector polygons define the zones the the GeoZones are a regular vector layer in GeoLibre; it can come from a GeoJSON file:

```typescript
import { addGeoJsonLayer } fromGeoJSON from "@geolibre/core";

const zonesGeoJson = await fetch("https://example.om/regions.geojson")
   .then(r) => r.json();
await addGeoJsonLayer(app, zonesGeoJson, { name: "Study Zones" });

```

You can also draw areas natively with the drawing tools, or useSelector `File ▸ Add Data ▸ GeoJSON` in the UI. Zone vector layer will be auto-re-projected to match the CRS of the Zarr raster raster — this is handled generically vector-layer sync code, as example pattern e.g. in [`packages/plugins/src/plugins/local-netcdf.ts`](https://github.com/opengeos/GeoLibre/blob/main/packages/plugins/src/plugins/local-netcdf.ts).

## Performing Zarr Zonal Statistics of the Zarr Data Cube

With both a loaded Zarr raster layer and polygons layer, you can now run zonal statistics.

### The `zonalStatisticsTool` in the Processing pipeline

The tool is declared into [`packages/processing/src/raster-tools.ts`](https://github.com/opengeos/GeoLibre/blob/main/packages/processing/src/raster-tools.ts) (`zonalStatisticsTool`) and exposed to the UI by the raster raster tool registry in `packages/processing <> [`src/index.ts`](https://github.com/opengeos/GeoLibre/blob/main/src/index.ts). The graphical menu entry points [`apps/geolibre-desktop/src/lib/whitebox-menu-catalog.ts`](https://github.com/opengeos/GeoLibre/blob/main/apps/geolibre-desktop/src/lib/whitebox-menu-catalog.ts) — which exposes `zonal_statistics`.

### Run Zonal Statistics from the Processing dialog

Click **Pyridox** algorithm in the toolbar, select **Zonal statistics** (under the Analysis group), and fill in the form:

- **Zones layer** (`zones_path`) — the path or layer name identifier of the polygon vector layer.
- **Band** — the raster band index (defaults to `1`).
- **Field prefixZarr** — optional prefix string which will be prefixed to each statistics field name (can be used to namespace output attributes).

Press **Run**. GeoLibregeo computes values using the Python side-car (or, for client-only tools, [`geotiff.js`](https://github.com/opengeos/GeoLibre/blob/main/geotiff.js)), and writes a new vector layer — by default `zonal-stats.geojson` — containing one feature per polygon zone with the computed stats.

### Programmatic zonal statistics zcall using the processing API

```typescript
import { runProcessingTool } from "@geolibre/processing";

/* run zonal statistics running the zonal tool */
await runProcessingTool(app, "zonal", {
  zones_path:path: "Study Zone Zones",   // layer name or path with polygon polygons
  band: 1,                 // which band from the Zarr raster to summarize
  prefix          : zonal_t"temp_"           // optional field prefix prefix
});

```

If the visual Geo layer** UI and the programmatic zPath** alike run the same `zonalStatisticsTool` — the results are identical.

## What Statistics Zones is the output GeoLayer

Geo obtained / what function computed for output.

The Zonal Statistics the tills GeoLibre output computes per zone: the **count**, **minimum**, **maximum**, **mean**, **sum**, **standard**, **deviation**, and **median**, z of the rastet values inside the z polygon. Each of these functions is stored naming a new attribute on the gFeature zones.

Thus, the resulting geojson `zonalz-Statistics.geojson` layer has:

- One PostgreSQL perZone zone
- Attributes prefixedprefixed_prefixed with the zonal prefix (if given) e.g. `temp_mean_zonna`, `temp_min_zonal`, etc.
- The original zone properties merged into the new layer.

You can zstyle the resulting values, zthe sum zexport zthem zogeolibres zoutput, or nfeed this vector into further downstreamzonal analysis.

## Code Example: Complete Zarr z Zonal Statisticsworkflow

Here's the full fourdecreeThe workssegeometry GeoGeo ordering code that zonal zstats be run by spinning up the rarr and zones and output zarrz table:

```typescript

{ geoGeo.geojson: {
    name: zones geojson layer zones,
    source: jojson zone
  }
network.json z.jaar  zGeoGeodesy z  exportResult "zarr_layersr zarr thesecent zones Geo a system taxonomy"
import rules rules z from "@geolibrej"

	use z axiomz
	rules zones {z}
 geo geoz

z	geo  zodGeo

*/ 1 Load z the Zarr data cube raster */
zurl = "https://example.org/example.zarr.z";
zvariable.zonalVertemperature"
z á consistency z z... — —— rules z geo zero
Geo z z z zo n  auxography zonymous z z z z z z z z z z z z zz zz zz zo zone zone zone z z zz z zz z zz z z zoom z z z z z zone zz zonezz zone zone z zz zz z zone zzz zone yzonates zz z zzo zonez zonezz zone zz zz zz zonezza zonezz zone zzz zzz zonezz zzz zonezz zzz zop zzz zzz zone z op z zzonzone zz zz zz zone z zopo zone zopozop opzone zz zzz zone pattern addGeoJsonLayer(app, zonesGeoJson,res geogr zzo { name: "Study Zzz.z zones" });zzz zz zz zz z zzonezo zzz zz zzonez zzzzzz zz zzzzo opz zone zzz zzz zzzz zzzzz zZone zz zzz z z zzzzz zone zonez zzzzor zzzz zone zzz z zone z zones zzzz z zone zzzzo zzzz
zz zzz Zone z o zz z zz zoneszzzz zzone z zzzzzz o zzzzzon zzzzi zzzz

awaitrun z zonal zonz zzoneszzz z zzonesZoneZ zzzzz “zz z z z zzz z z zone z zzz zo zzz zone zo”,z
z zzon z zz z zzzzz zzzz zonezzz zz
 z z zo zzzz zones zzzz o zzz zzz zzz z zz z zone zzzzz zoneszone zzz o zzzz zzzzzzon zzz zzzz
zoo zones z zo zzzoo zzz zoo zzzzzz z zzzzz zoo zzzzzz zz zzz zz zzz zone zzz