IraqAdminDivisions.AspNetCore 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package IraqAdminDivisions.AspNetCore --version 1.0.1
                    
NuGet\Install-Package IraqAdminDivisions.AspNetCore -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IraqAdminDivisions.AspNetCore" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IraqAdminDivisions.AspNetCore" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="IraqAdminDivisions.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IraqAdminDivisions.AspNetCore --version 1.0.1
                    
#r "nuget: IraqAdminDivisions.AspNetCore, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IraqAdminDivisions.AspNetCore@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IraqAdminDivisions.AspNetCore&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=IraqAdminDivisions.AspNetCore&version=1.0.1
                    
Install as a Cake Tool

IraqAdminDivisions

العربية

Every Iraqi governorate, district and sub-district in Arabic, English and Kurdish, with stable codes, search, full addresses in every language, and offline GPS-to-address lookup. One NuGet package, no lookup tables, no network calls.

NuGet Downloads NuGet Boundaries NuGet AspNetCore CI License: MIT

Why

Address forms in Iraq usually end up with lookup tables for governorates, districts and sub-districts, foreign keys, seed scripts and a column per language. This package replaces all of that with one string column: store the code of the area, and the library gives you its names, its parents and the full address in Arabic, English and Kurdish.

  • Codes are OCHA P-codes, already used by UN and NGO datasets.
  • Codes are hierarchical, so "all customers in Baghdad" is a single LIKE 'IQG08%'.
  • Everything is embedded in the assembly: offline, no database, no API.

Packages

Package What it adds Size
IraqAdminDivisions Names, codes, hierarchy, search, addresses, validation small
IraqAdminDivisions.Boundaries Locate(lat, lng): GPS point → sub-district → district → governorate + polygons
IraqAdminDivisions.AspNetCore app.MapIraqDivisions(): ready endpoints for dropdowns tiny
dotnet add package IraqAdminDivisions
dotnet add package IraqAdminDivisions.Boundaries   # optional: GPS → address
dotnet add package IraqAdminDivisions.AspNetCore   # optional: HTTP endpoints

Targets netstandard2.0 and net8.0 (.NET Framework 4.6.1 up to current .NET). Trimming and Native AOT compatible on .NET 8+.

Quick start

1. Store one code

public class Customer
{
    public int Id { get; set; }

    [IraqDivisionCode(AdminLevel.SubDistrict)]
    public string AreaCode { get; set; } = "";      // "IQG07Q02N02"

    public string Landmark { get; set; } = "";      // free text, e.g. near a mosque
}

2. Show the address in one language, or all three

IraqDivisions.FormatAddress("IQG07Q02N02", Language.Arabic);   // ابي غرق، الحلة، بابل
IraqDivisions.FormatAddress("IQG07Q02N02", Language.English);  // Abi Gharaq, Al-Hilla, Babil

var address = IraqDivisions.GetAddress("IQG07Q02N02");
address.Ar;   // ابي غرق، الحلة، بابل
address.En;   // Abi Gharaq, Al-Hilla, Babil
address.Ku;   // ئەبی غەرەق، حیللە، بابل

Or each part on its own:

var area = IraqDivisions.Find("IQG07Q02N02")!;
area.Name.Ar;               // ابي غرق
area.District!.Name.Ar;     // الحلة
area.Governorate.Name.Ar;   // بابل

3. Filter by governorate or district in your database

A child's code always starts with its parent's code:

IQG08Q03N03   Al-Mansour sub-district
IQG08Q03      Al-Karkh district
IQG08         Baghdad governorate

So EF Core needs no join and no lookup table:

db.Customers.Where(c => c.AreaCode.StartsWith("IQG08"));      // all of Baghdad
db.Customers.Where(c => c.AreaCode.StartsWith("IQG08Q03"));   // Al-Karkh only
// SQL: WHERE "AreaCode" LIKE 'IQG08%'   (can use an index)

From a search box ("بغداد", "baghdad", even "بغدات"):

var place = IraqDivisions.Search("بغداد")[0].Division;          // IQG08
db.Customers.Where(c => c.AreaCode.StartsWith(place.Code));

On PostgreSQL, give the column a text_pattern_ops index (or C collation) so LIKE 'prefix%' uses it.

4. Only governorate → area? (two dropdowns)

Many apps don't want districts and sub-districts. Localities is one flat list of the areas of a governorate (districts plus sub-districts, without the "Markaz X" duplicates):

IraqDivisions.Governorates;                       // first dropdown
IraqDivisions.Find("IQG07")!.Localities;          // second dropdown: Al-Hashimiya, Al-Qasim, Al-Shomaly, Al-Madhatiya, Al-Hilla, ...

Store the chosen area's code; FormatAddress, GetAddress and the StartsWith filters work the same.

5. GPS → address (Boundaries package)

using IraqAdminDivisions.Boundaries;

var area = IraqBoundaries.Locate(33.3340, 44.4170);                       // sub-district, or null outside Iraq
var governorate = IraqBoundaries.Locate(lat, lng, AdminLevel.Governorate);
IraqBoundaries.Contains("IQG08", lat, lng);                               // is this point in Baghdad?

Point-in-polygon over the real OCHA boundaries, not the nearest centre.

6. ASP.NET Core endpoints

using IraqAdminDivisions.AspNetCore;

app.MapIraqDivisions();                      // default prefix /api/iraq-divisions
app.MapIraqDivisions("/api/divisions")       // or your own; returns a RouteGroupBuilder
   .RequireAuthorization();
Endpoint Returns
GET /governorates All governorates
GET /{code} One division
GET /{code}/children Its children (cascading dropdowns)
GET /{code}/localities Flat area list of a governorate
GET /search?q=&level=&limit= Search results with scores
GET /nearest?lat=&lng=&level= Nearest division centre

Language: ?lang=ar|en|ku or the Accept-Language header. Every item carries name, names {ar,en,ku}, address, addresses {ar,en,ku} and kurdishNameSource.

API

Member Description
IraqDivisions.Governorates / All The 19 governorates / all 414 current divisions
IraqDivisions.Find(code) Division by code (case-insensitive, trimmed), including deprecated codes, or null
IraqDivisions.IsValid(code, level?) Is the code current (not deprecated) and of that level; use it for new input
IraqDivisions.FormatAddress(code, language) Full address in one language
IraqDivisions.GetAddress(code) Full address in Arabic, English and Kurdish
IraqDivisions.Search(query, limit, level?) Tolerant search: ه/ة, ي/ى, أ/إ/ا, tashkeel, "ال", "Al-", one typo
IraqDivisions.Nearest(lat, lng, level) Nearest division centre (approximate; use Locate for exact)
Division.Name / Address Ar, En, Ku, Get(language)
Division.Parent / Children / District / Governorate Hierarchy, pre-linked
Division.Localities Flat area list (governorates only)
Division.KurdishNameSource / KurdishNameDataset Wikidata, Dataset (+ which one), Transliterated or Manual
Division.IsoCode ISO 3166-2 code of a governorate (IQ-BG, ...)
Division.OchaCode The original OCHA P-code, for joining with UN/NGO data
Division.IsDistrictCentre The "Markaz X" sub-district of a district
Division.Latitude / Longitude / AreaSqKm / WikidataId / Aliases Extra data
Division.IsDeprecated / ReplacedByCode Code lifecycle
[IraqDivisionCode(level?)] DataAnnotations validation
IraqBoundaries.Locate(lat, lng[, level]) / Contains(code, lat, lng) GPS lookups (Boundaries package)

Performance

Measured with BenchmarkDotNet on .NET 10 (benchmarks/). All data is loaded once, lazily and thread-safely.

Operation Mean Allocated
Find 17 ns 0 B
FormatAddress / GetAddress 16 ns 0 B
Localities 8 ns 0 B
Search (Arabic, English, one typo) 8 µs ~250 B (the result list)
First load of all divisions 0.7 ms
IraqBoundaries.Locate (point in Baghdad / random point) 56 ns / 35 ns 0 B
IraqBoundaries.Locate (point outside Iraq) < 1 ns 0 B
First load of the boundaries (parse + spatial index) ~25 ms ~3 MB retained

Locate uses a 0.05° grid where each cell is pre-classified as inside one area, outside, or on a border; border cells only test the polygon edges that cross them. It returns exactly the same results as a brute-force point-in-polygon check (verified on 400,000+ points).

Data and coverage

Level Count Kurdish from Wikidata from an open dataset transliterated manual
Governorate 19 18 0 0 1
District 101 49 38 14 0
Sub-district 294 29 64 200 1
Total 414 96 102 214 2

Every division has Arabic, English and Kurdish names; every sub-district has a boundary polygon. Full reports: reports/build-report.md and reports/kurdish-crosscheck.md.

About the Kurdish names

  1. Wikidata first, when a confident match exists (same name, same parent, close enough).
  2. Open datasets next. Three open Iraqi datasets were compared against our 96 Wikidata names; only one, aryzonedev/iraq-cities (CC BY 4.0), agreed with Wikidata often enough (81% beyond governorate level) to be used. Its names fill 102 rows (KurdishNameDataset says which). This is a calibrated source, not proof of native review. karam-fikre/iraqi-data was used only for comparison because its own documentation calls its Kurdish names unreviewed drafts.
  3. Transliterated: the remaining 214 names are AI-assisted transliterations from the Arabic and English names in Sorani orthography (e.g. ة → ە, "مركز X" → "ناوەندی X"), using the known local Kurdish name where one is well established (e.g. Altun Kupri → پردێ). They read correctly but have not been reviewed by a native speaker.

Each name says where it came from, so you decide what to show:

var kurdish = area.KurdishNameSource == KurdishNameSource.Transliterated
    ? area.Name.Ar          // or show it with a "machine transliterated" hint
    : area.Name.Ku;

Corrections from Kurdish speakers are the most valuable contribution to this project.

How the data is built

tools/IraqAdminDivisions.Builder produces data/divisions.json and data/boundaries.json, which are committed and embedded in the packages.

  1. Base: OCHA COD-AB Iraq v01: codes, Arabic and English names, centres, areas and boundaries.
  2. Kurdish: Wikidata ckb labels matched by name + parent + distance; name-only matches are rejected; type prefixes ("پارێزگای", "قەزای") are stripped; anything that is not pure Sorani is rejected.
  3. Open datasets: vendored at pinned commits in data/sources/, calibrated against Wikidata before use (see reports/kurdish-crosscheck.md).
  4. Overrides: data/overrides/corrections.tsv fixes source errors, each with a reason (e.g. OCHA lists Baladruz district with the Arabic name of Mandali); data/overrides/kurdish-transliterated.tsv fills the remaining Kurdish names; data/overrides/restructures.json applies legal changes OCHA has not caught up with (Halabja). Replaced values stay searchable as aliases.
  5. ISO 3166-2: governorate codes from Wikidata (P300), validated as unique IQ-XX.
  6. Boundaries: OCHA polygons simplified with Douglas-Peucker (~11 m tolerance); every division's centre lies inside its own polygon.
  7. Validation: the build fails on wrong counts, duplicate or non-hierarchical codes, a deprecated code without a current replacement, missing names in any language, non-Sorani Kurdish, a bad ISO code, or a sub-district without a polygon.
  8. Not used: OpenStreetMap (ODbL share-alike) and GADM (no commercial use).

A scheduled workflow re-runs the builder monthly and opens a pull request when the sources change.

Halabja Governorate

Halabja became Iraq's 19th governorate by law (passed by the Council of Representatives on 2025-04-14, published in the Official Gazette on 2025-05-05). OCHA COD-AB v01 still lists it as a district of Sulaymaniyah, so the package applies the change on top of OCHA with data/overrides/restructures.json:

Code What
IQG19 Halabja Governorate (code assigned by this project; no confirmed ISO 3166-2 code yet)
IQG19Q01, IQG19Q01N01…N04 The OCHA district and its four sub-districts, moved unchanged; OchaCode keeps IQG06Q05…
IQG06Q05, IQG06Q05N01…N04 Old codes: still resolve through Find, flagged IsDeprecated, ReplacedByCode points to the new code

So StartsWith("IQG06") (Sulaymaniyah) no longer returns Halabja rows. Federal sources list the sub-districts as Sirwan, Khurmal, Biyara and Bamo, while OCHA has Biyara, Khurmal, Markaz Halabja and Shahrazur: Sirwan and Bamo have no OCHA geometry yet, and Shahrazur's placement is unconfirmed. This will be revisited when OCHA publishes a new version.

Limitations

  • 214 Kurdish names are transliterated and 102 come from a calibrated open dataset; neither is native-reviewed (see above).
  • No neighbourhoods (mahallas) yet; keep a free-text landmark next to the code.
  • Halabja's internal composition follows OCHA, not the federal list (see above). The Sulaymaniyah governorate polygon in the GeoJSON export still includes Halabja; Locate is unaffected because it works on sub-districts.
  • Arabic spellings follow OCHA (e.g. "ابي غرق" without hamza); search ignores the difference.

Code stability

A published code is never removed or reused. If a division changes, its old code still resolves, is flagged IsDeprecated and points to its successor through ReplacedByCode, so updating the package never breaks stored data. A snapshot test checks every released code, and package validation blocks breaking API changes.

Quality

  • Tests run on .NET 8, .NET 10 and .NET Framework 4.8 (the netstandard2.0 build).
  • 100% line coverage of the core and ASP.NET Core packages; the Boundaries package checks every division centre plus known city points (including Halabja) and points outside Iraq, and proves its fast path returns exactly what a brute-force point-in-polygon check returns.

Data exports (non-.NET users)

File Format
data/divisions.json Source of truth, all levels
data/exports/divisions.csv CSV (UTF-8 with BOM, opens in Excel)
data/exports/divisions.sql SQL (PostgreSQL / generic)
data/exports/divisions.sqlserver.sql SQL Server (NVARCHAR, N'...')
data/exports/divisions.geojson GeoJSON with boundaries, all levels

Contributing

Found a wrong or missing name, especially a Kurdish one? Open a data correction issue or a PR to the files in data/overrides/ with a source. See CONTRIBUTING.md.

Attribution

Administrative divisions and boundaries: UN OCHA, Common Operational Dataset - Administrative Boundaries (COD-AB) Iraq, via the Humanitarian Data Exchange, licensed under CC BY-IGO 3.0. The data was modified (corrected, restructured for Halabja, merged with Wikidata labels, dataset names and transliterations, simplified and re-exported). This is not an official UN or OCHA product. Kurdish names: Wikidata (CC0), aryzonedev/iraq-cities (CC BY 4.0) and this project. See DATA_LICENSE.md.

License

Code: MIT. Data: CC BY-IGO 3.0 (OCHA), CC0 (Wikidata) and CC BY 4.0 (aryzonedev/iraq-cities), see DATA_LICENSE.md.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 95 11/8/2026
1.0.1 92 11/8/2026