A curated repository providing GeoJSON data for Kenya's wards as established by the 2010 constitution and adopted in the 2019 census. This project serves as a practical resource for developers and GIS analysts to learn and implement spatial queries using PostGIS (for PostgreSQL) and Spatialite (for SQLite).
# Kenya Geospatial Data
Kenya administrative boundary data (counties, constituencies, wards) with PostGIS and SpatiaLite geometry support via Drizzle ORM. Targets PostgreSQL, PGlite (in-browser WASM Postgres), Cloudflare D1, and SQLite/SpatiaLite.
**Data source:** Kenya Elections — Humanitarian Data Exchange
Source shapefiles are not committed to the repo. A download script fetches them on demand from humdata.org.
## Data overview
| Level | Records | Geometry | Source CRS |
|----------------|---------|----------------|------------|
| Counties | 47 | MultiPolygon | EPSG:4326 (WGS84) |
| Constituencies | 290 | MultiPolygon | EPSG:4326 (WGS84) |
| Wards | 1,450 | Polygon / MultiPolygon | EPSG:3857 (Web Mercator) |
The ward shapefile is in **EPSG:3857** (Google Maps Global Mercator — coordinates in meters, not degrees). Counties and constituencies are already in WGS84. The extract script reprojects ward coordinates from 3857 to 4326 at extraction time, so all output GeoJSON files are in **EPSG:4326 (WGS84)**.
## Schema
Tables use the `kenya_` prefix. Foreign keys reference `id` (not `code`), matching the consuming project's schema:
```
kenya_counties (47)
├── kenya_constituencies (290) FK → kenya_counties.id
│ └── kenya_wards (1,450) FK → kenya_constituencies.id
├── kenya_governors FK → kenya_counties.id, kenya_parties.id
├── kenya_mps FK → kenya_constituencies.id, kenya_parties.id
└── kenya_mcas FK → kenya_wards.id, kenya_parties.id
kenya_parties
```
PG schema (`src/schema/pg.ts`) uses `geometry(MultiPolygon, 4326)` via a Drizzle `customType` — workaround for drizzle-orm#3040.
D1 schema (`src/schema/d1.ts`) mirrors PG exactly but stores geometry as `text` (GeoJSON string). This means pulling rows from D1 into PGlite requires only `ST_GeomFromGeoJSON(text)` — no hacks, the data feels native to PostGIS.
SpatiaLite schema (`src/schema/spatialite.t …