feat: postal codes from GeoNames for the ISTAT municipalities (#45)

The municipalities now come with their postal codes, so the lookup from
postal code works on a new company without loading anything. GeoNames
(CC BY 4.0) lists places rather than municipalities: a postal code goes
to a municipality only when the name and the province abbreviation match
exactly one of them (the name alone within Sardinia, whose abbreviations
changed), which covers 7,750 of 7,894 municipalities; the rest are mostly
renamed or merged ones that users complete by hand.

tools/Khaemhat.PlacesTool rebuilds both lists from the ISTAT sheet and
the GeoNames file, framework only, so the yearly update is repeatable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-12 09:16:07 +01:00
1 parent 321aae7e81
commit a9eda510f2
15 files changed
+8192 -7936

No files matched your search

File diff suppressed because it is too large. Load diff
+6 -4
View File
@@ -5,13 +5,15 @@ namespace Khaemhat.Fiscal.Italy;
/// <summary>
/// The Italian provinces and municipalities from the ISTAT list of municipality codes (ADR 0028): abbreviation, name and
/// region of the 110 provinces, and cadastral code, name, province, region and ISTAT code of every municipality. The
/// list has no postal codes. The files are read once, the first time they are needed.
/// region of the 110 provinces, and cadastral code, name, province, region and ISTAT code of every municipality, with
/// the postal codes of GeoNames where they match (about 98% of the municipalities). The files are rebuilt with
/// <c>tools/Khaemhat.PlacesTool</c> and read once, the first time they are needed.
/// </summary>
public sealed class ItalianPlaces : IPlaceDirectory
{
/// <summary>The source of the embedded files.</summary>
public const string ListSource = "ISTAT, Codici statistici delle unità amministrative territoriali, 26/02/2026 (CC BY 4.0)";
public const string ListSource =
"ISTAT, Codici statistici delle unità amministrative territoriali, 26/02/2026 (CC BY 4.0); CAP: GeoNames, www.geonames.org (CC BY 4.0)";
private readonly Lazy<IReadOnlyList<ProvinceTemplate>> _provinces = new(ReadProvinces);
private readonly Lazy<IReadOnlyList<MunicipalityTemplate>> _municipalities = new(ReadMunicipalities);
@@ -29,7 +31,7 @@ public sealed class ItalianPlaces : IPlaceDirectory
[.. Read("province.csv").Select(l => new ProvinceTemplate(l[0], l[1], l[2]))];
private static IReadOnlyList<MunicipalityTemplate> ReadMunicipalities() =>
[.. Read("comuni.csv").Select(l => new MunicipalityTemplate(l[0], l[1], l[2], l[3], l[4], null))];
[.. Read("comuni.csv").Select(l => new MunicipalityTemplate(l[0], l[1], l[2], l[3], l[4], l.Count > 5 && l[5].Length > 0 ? l[5] : null))];
private static List<IReadOnlyList<string>> Read(string file)
{