Sooner or later, an app made for Algeria needs the country's administrative map. A wilaya dropdown in an address form. A commune picker under it. A choropleth map of sales per wilaya. A function that takes GPS coordinates and answers "which commune is this?".
The data for this exists in pieces. One list has the names in French only, another has outlines without codes, a third still shows 48 wilayas. Boundaries downloaded from different places do not line up, so a map drawn from them has gaps and slivers between neighbours. And almost nobody ships the hierarchy: which commune belongs to which daïra, and which daïra to which wilaya.
dz-geodata is one dataset that answers all of these: 69 wilayas, 548 daïras and 1,538 communes, as GeoJSON and TopoJSON, with Arabic, French and English names, ONS commune codes and the links between levels. It is built reproducibly from OpenStreetMap, and it comes with JavaScript and Python packages that have lookup helpers.
What it does
The files. Everything lives in the data/ folder:
-
wilayas.geojson: 69 wilayas withcode("01" to "69"),name_ar,name_fr,name_en,osm_idandwikidata. -
dairas.geojson: 548 daïras with theirwilaya_code, names,osm_idandwikidata. -
communes.geojson: 1,538 communes withons_code,wilaya_code,daira_osm_id, names,population(as tagged in OSM),osm_idandwikidata. -
algeria.topojson: all three levels as one topology with shared arcs, 1.6 MB. -
*.json: the same attributes without geometry, for dropdowns and lookups. -
provenance.json: the source, the extract date and its SHA-256, the counts and the simplification settings.
Borders that still match. The geometries are simplified with Douglas–Peucker at 0.0005° (about 55 m), but the simplification is done on shared arcs. Two neighbouring communes share one border line, and that line is simplified once. The result: no gaps and no slivers between units. GeoJSON coordinates are rounded to 5 decimals.
Lookup helpers. The JavaScript and Python packages offer the same functions: wilayas, wilaya(code) (which accepts 16, "16" or "DZ-16"), dairas(w), daira(osm_id), communes(w), commune(ons), search(q, level, limit), locate(lon, lat) and normalize.
Search that forgives spelling. search ignores case, accents and Arabic diacritics, and it unifies alef, ta marbuta and alef maqsura variants. So bejaia finds Béjaïa, and so does بجاية. Exact matches rank above prefix matches, which rank above substring matches.
Reverse geocoding. locate(lon, lat) returns the commune, daïra and wilaya that contain a point.
How to use it
If you only need the data, clone the repository and take the files from data/:
git clone https://github.com/AbdeldjalilChougui/dz-geodata
ls dz-geodata/data
The packages live in packages/npm and packages/python. Their copy of the data is not committed, so copy it in first with the repository's sync script, then install from the local path:
cd dz-geodata
uv sync
uv run python scripts/sync_packages.py # copy data/ into packages/
npm i ./packages/npm # in your JavaScript project, use the path to this folder
pip install ./packages/python # same for Python
In JavaScript:
import { wilaya, communes, commune, search, locate } from "dz-geodata";
wilaya(16).name_ar; // "الجزائر"
search("بجاية")[0].name_fr; // "Béjaïa"
locate(-0.6417, 35.6971); // { commune, daira, wilaya: { code: "31", ... } }
In Python:
import dz_geodata as dz
dz.commune("1601"); dz.communes(wilaya_code=31); dz.search("bejaia"); dz.locate(3.0588, 36.7538)
Rebuilding from OpenStreetMap. You need uv and GDAL's ogr2ogr with the OSM driver:
uv sync
uv run python scripts/build.py # downloads the Geofabrik extract (~300 MB) into raw/ if missing
uv run python scripts/sync_packages.py # copy data/ into packages/
uv run pytest # validate data/
The README says the build takes about 6 minutes on a laptop, mostly ogr2ogr reading the PBF file. The steps are:
-
Extract administrative boundaries at
admin_level4, 6 and 8 from the Geofabrik Algeria extract. -
Filter to Algeria. Wilayas are those tagged
ISO3166-2=DZ-*, or with a numericreffrom 1 to 69 when a new wilaya lacks the ISO tag. A daïra or commune is kept when its interior point falls inside a wilaya, which drops the Moroccan and Tunisian units that the extract includes along the border. - Fix known OSM inconsistencies. A newly created wilaya that is still nested inside its parent is subtracted from it. Duplicate relations covering the same area keep the better-tagged one.
-
Names.
name:ar,name:frandname:en, with administrative prefixes such as "Wilaya d'" or "بلدية" stripped.name_enfalls back toname_frwhen OSM has no English name. - Hierarchy. Commune to daïra and commune to wilaya, by point-in-polygon.
- Topology. Rings are cut at junctions into shared arcs, each arc is simplified once, and shapes that would self-intersect are re-simplified more finely. Then TopoJSON and GeoJSON are written.
Things to know
The README is direct about the limits, and they matter:
-
This is OSM data, as of the extract date in
provenance.json. It reflects the 2025 reorganisation into 69 wilayas wherever OSM does. For legal use, check against official sources (ONS, Journal officiel). -
ONS codes are as tagged in OSM (
ref:ONS). They follow the historic numbering, so a commune now in a wilaya created in 2019 or 2025 keeps its old prefix: a commune of wilaya 58 may still start with 47. One commune (Aïn Defla) has no code in OSM. - Missing communes. A few commune relations are broken in OSM and cannot be assembled. That leaves holes: about 3.6% of Alger's area and 10.6% of Ghardaïa's. 1,538 communes are present out of 1,541 official ones.
-
Daïras have no official code in OSM, so they are identified by
osm_id. -
Not survey-grade. The boundaries are simplified for web maps. Rebuild with
--tolerance 0for full detail.
What is tested. uv run pytest runs 25 validation tests on the data. They check the counts (69 wilayas with codes exactly "01" to "69", unique 4-digit ONS codes on at least 99% of communes), the names (Arabic script in name_ar, none in name_fr, no leftover prefixes), the geometry (every shape valid and inside Algeria's bounding box, communes tiling their wilaya with at least 98% coverage and at most 1% overlap, with the known exceptions above), and the hierarchy (every commune's daïra is in the same wilaya, the TopoJSON decodes to the same features and areas as the GeoJSON). The npm package has 5 tests and the Python package 6, covering lookups, search ranking in the three languages and locate.
Why I built it
Because this is groundwork that every Algerian project redoes. The usual path is to copy a list of wilayas from an older project, discover it is out of date, find boundary files somewhere else, and then spend an evening matching names that are spelled three different ways. After the move to 69 wilayas, most of the old lists are simply wrong.
I wanted one source where the names, the codes, the shapes and the hierarchy agree with each other, where the origin of every file is written down, and where the whole thing can be rebuilt from a fresh OpenStreetMap extract with one command when the map changes again. The validation tests are part of that: they are what tells you a new build is still a usable map and not a broken one.
Get the code
The data, the build scripts and both packages are on GitHub: https://github.com/AbdeldjalilChougui/dz-geodata. The code is MIT licensed. The data is under ODbL 1.0, © OpenStreetMap contributors, so keep the attribution in any map or app that uses it. If you see a boundary or a name that is wrong, the best fix is often in OpenStreetMap itself, and the next rebuild will pick it up.
Originally published at abdeldjalilchougui.biz.
Top comments (0)