---
id: "pfafstetter_code"
kind: "datatype"
status: "draft"
is_pii: false
name: "Pfafstetter basin code"
regexp: "^\\d{1,12}$"
categories: ["environment", "geo"]
langs: ["common"]
quality: 90
url: "https://registry.apicrafter.io/datatype/pfafstetter_code"
---

# Pfafstetter basin code (`pfafstetter_code`)

> **Draft.** Draft records have not been reviewed yet and may be incomplete or wrong; do not treat them as authoritative for legal or compliance decisions.

Code of a river basin in the Pfafstetter coding of Otto Pfafstetter: at every level the four largest tributary basins are numbered 2, 4, 6 and 8, the interbasins between them 1, 3, 5, 7 and 9 and a closed basin 0, so a code of n digits is a basin of level n inside the basin named by its first n-1 digits. South American hydrographic units are coded this way (in Bolivia 4 the Amazon, 8 La Plata and 0 the closed Altiplano basin; 85899 a unit of the Guadalquivir in Tarija), as are the ottobacias of the Brazilian water agency ANA and the PFAF_ID of the global HydroBASINS. Leading zeros are part of the code (015).

- Parent datatype: [`id`](https://registry.apicrafter.io/datatype/id.md)
- Personal data (PII): no
- Categories: Environment (protected areas, biodiversity, water, weather, emissions, waste) (environment), Geographic identifiers (geo)
- Countries: global
- Languages: Common to most languages (common)
- Classification: identifier

## Detection

Regular expression (Python `re`):

```
^\d{1,12}$
```

## Examples

- `85899` — level 5, Río Guadalquivir (Tarija, Bolivia)
- `8589929` — level 7, inside 85899
- `01592` — level 5 of the closed Altiplano basin (Katari, La Paz)
- `8a` (invalid example) — digits only

## Metacrafter rules

2 rules: 2 match the field name, 0 match values.

- `pfafstettercodebyname` (field, `common/geo.yaml`)
- `pfafstetterlevelbyname` (field, `common/geo.yaml`)

## Supported by tools

- [`metacrafter`](https://registry.apicrafter.io/tool/metacrafter.md)

## Translations

- es: Código Pfafstetter de cuenca
- pt: Código de Pfafstetter (ottobacia)

## Sources

- wikipedia: <https://en.wikipedia.org/wiki/Pfafstetter_Coding_System>
- other: <https://www.hydrosheds.org/products/hydrobasins>

## Quality

Score 90/100. Missing: mapping (Wikidata, Schema.org, ...).

JSON: <https://registry.apicrafter.io/api/v1/datatypes/pfafstetter_code.json> · Edit: <https://github.com/apicrafter/metacrafter-registry/edit/main/data/datatypes/any/environment/pfafstetter_code.yaml>
