]> git.openstreetmap.org Git - nominatim.git/blob - docs/develop/Postcodes.md
8b532162abe92e2d3c93bb2348697cf6302009ef
[nominatim.git] / docs / develop / Postcodes.md
1 # Postcodes in Nominatim
2
3 The blog post [Nominatim and Postcodes](https://www.openstreetmap.org/user/lonvia/diary/43143)
4 describes the new handling in Nominatim 3.1.
5
6 Postcode centroids (aka 'calculated postcodes') are generated by looking at all postcodes of
7 a country, grouping them and calculating the geometric centroid. There is currently no logic
8 to deal with extreme outliers (typos or other mistakes in OSM data). There is also no check
9 if a postcodes adhere's to a countries format, e.g. if Swiss postcodes are 4 digits.
10
11
12 ## Regular updating calculated postcodes
13
14 The script to rerun the calculation is `build/utils/update.php --calculate-postcodes` and
15 runs once per night on nominatim.openstreetmap.org.
16
17
18 ## Finding places that share a specific postcode
19
20 In the Nominatim database run
21
22 ```sql
23   SELECT osm_type, osm_id, class, type, st_x(centroid) as lon, st_y(centroid) at lat
24   FROM placex 
25   WHERE country_code='fr'
26     AND upper(trim (both ' ' from address->'postcode')) = '33210';
27 ```
28
29 Alternatively on [Overpass](https://overpass-turbo.eu/) run the following query
30
31 ```
32 [out:json][timeout:250];
33 area["name"="France"]->.boundaryarea;
34 (
35 nwr(area.boundaryarea)["addr:postcode"="33210"];
36 );
37 out body;
38 >;
39 out skel qt;
40 ```