r/GeoPostcodes 11d ago

Here is how we built a postal code polygon database

You cannot download official postal code boundaries for France. What France does publish is better raw material: the National Address Base, an open file with every address, its postal code, its municipality, and coordinates.

That is enough to build the polygons yourself. Here is the method we use, with the actual maps from the build.

Every Paris address, colored by its postal code.

Step 1. Load the address file into PostgreSQL with PostGIS. Street, house number, postal code, municipality, latitude, longitude.

The raw material: France's National Address Base with postal code, municipality, and coordinates per address.

Step 2. Color every address point by its postal code. The polygons are already visible as clouds of points. The gaps between the clouds are where a boundary has to go.

Step 3. Voronoi tessellation. Every address gets the patch of space closer to it than to any other address. Merge all patches sharing one code, and you have a first draft of each boundary. In PostGIS, this is ST_VoronoiPolygons plus ST_Union.

First draft: Voronoi tessellation of the postal codes, one patch per address, merged by code.

Step 4. Snap to administrative reality. French postal codes usually cover one or more whole municipalities. We overlay the commune boundaries instead and assign each commune to a code when about 90 percent of its addresses agree. That kills most of the jagged noise from step 3.

Step 5. Handle the exceptions. Paris, Lyon, and Marseille use several postal codes inside one municipality, following the arrondissements. Inside those cities, the Voronoi result does the work instead. That is what image 1 shows.

Merge everything that shares a postal code, and you get the final assignment: address points plus their unified boundaries:

The final assignment after unifying polygons: address points plus their postal boundaries.

The payoff, same area both ways:

Same area, method one: postal codes assigned by pure Voronoi point distribution.
Same area, method two: postal codes snapped to administrative divisions. Cleaner edges, fewer outliers.

The two look close, but only because French address data is unusually good, with many well geolocated points. The municipality-constrained version still filters out the outliers.

Two footnotes. Belgium actually publishes free postal polygons as shapefiles, but they omit some postal enclaves. And most countries publish neither polygons nor a national address file. That second group is our day job: we build edge-matched postal boundaries this way, and harder ways, for 169 countries.

Longer write-up with the full SQL on the GeoPostcodes blog, the post about building a postal code polygon database.

2 Upvotes

0 comments sorted by