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