# Raster datasets

> Where geolith dataset sits next to terrain and raster, the one reader all three share, and the files a dataset build writes.

## Overview

`geolith dataset` is the third consumer of gridded rasters in the builder, after
[`geolith terrain`](/builder/guides/terrain-3d) and
[`geolith raster`](/builder/guides/raster-basemap):

| Command           | Reads a raster as          | Writes                             |
| ----------------- | -------------------------- | ---------------------------------- |
| `geolith terrain` | elevation per cell         | Terrain-RGB PMTiles, 3D tiles      |
| `geolith raster`  | imagery tiles over HTTP    | An imagery PMTiles basemap         |
| `geolith dataset` | a value per cell, per date | A map layer plus a number per area |

All three go through the same reader, `terrain::Cog`: one tiled TIFF decoder over
a file, reading only the chunks a window needs. A dataset therefore reads a
1 GB COG with the same code path as a terrain DEM, and `geolith dataset inspect
<file>` exists to prove a new raster decodes — it prints the tags, then reads one
window through the DEM path and one through the `Cog` path, and reports both as
JSON on the last line.

## What makes a dataset raster different

- **A date in the name.** Each file is one period (a pentad or a dekad), named by
  the config's `file_template`. A directory of them is a series; the newest period
  becomes the map layer and each earlier one can be its own layer.
- **A normal, not just a value.** The same slot in a baseline window gives the
  normal, so a period carries a comparison as well as a value.
- **Aggregation, not rendering.** Pixels are aggregated into the polygons you
  supply, so the output that matters is `numbers.csv`, and the tiles are for
  looking at those numbers.

## Build your own

The full walkthrough — config, rasters, areas, normals, build — is
[Build a dataset from your own raster and your own areas](/datasets/build-your-own).
The short version:

```bash
geolith dataset normals --config demo.json --rasters baseline --areas areas.geojson \
    --baseline 2010-2010 --slots 10-1,10-2 --out normals.csv
geolith dataset build --config demo.json --rasters raster --areas areas.geojson \
    --normals normals.csv --out out
```

## Upload to your own store

`geolith dataset upload` and `publish` write to a bucket you configure; the binary holds no bucket, prefix or host of its own. Every setting has an environment name (`DATASETS_R2_ENDPOINT`, `DATASETS_R2_REGION`, `DATASETS_BUCKET`, `DATASETS_KEY_PREFIX`, the optional `DATASETS_R2_ACCOUNT` guard, `GEOLITH_STORAGE_ACCESS_KEY_ID`, `GEOLITH_STORAGE_SECRET_ACCESS_KEY`), kept in a mode-600 `.env` file copied from `.env.example`: the file `GEOLITH_ENV_FILE` names, else `.env` in the current directory. The store can be any S3-compatible one: Cloudflare R2, AWS S3, MinIO or Backblaze B2. A flag beats the process environment, which beats `.env`, which beats an optional JSON file named by `--config` (before the step) or `GEOLITH_CONFIG`; nothing under your home directory is read by default. `DATASETS_POINTER_URL` and `DATASETS_PAGE_URL` are optional URL templates for the live check of `geolith dataset refresh`; unset, the check is skipped. The walkthrough has the file and the guards: [Build a dataset from your own raster and your own areas](/datasets/build-your-own), step 7.

## Limits worth knowing

- The rasters of one build must share one grid. A file whose grid differs is
  refused by name, not resampled.
- A baseline range needs every year of it on disk, unless the values cache
  (`--cache <dir>`) already holds that raster's per-area values.
- Clip and boundary steps shell out to GDAL (`gdal_translate`) and `unzip`; those
  steps exit `3` naming the missing tool rather than guessing.
