2019-11-06 18:46:40 +03:00
|
|
|
# Postcodes in Nominatim
|
|
|
|
|
2019-11-12 01:34:44 +03:00
|
|
|
The blog post
|
|
|
|
[Nominatim and Postcodes](https://www.openstreetmap.org/user/lonvia/diary/43143)
|
2019-11-07 00:34:43 +03:00
|
|
|
describes the handling implemented since Nominatim 3.1.
|
2019-11-06 18:46:40 +03:00
|
|
|
|
2019-11-07 00:34:43 +03:00
|
|
|
Postcode centroids (aka 'calculated postcodes') are generated by looking at all
|
|
|
|
postcodes of a country, grouping them and calculating the geometric centroid.
|
|
|
|
There is currently no logic to deal with extreme outliers (typos or other
|
|
|
|
mistakes in OSM data). There is also no check if a postcodes adheres to a
|
|
|
|
country's format, e.g. if Swiss postcodes are 4 digits.
|
2019-11-06 18:46:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
## Regular updating calculated postcodes
|
|
|
|
|
2019-11-07 00:34:43 +03:00
|
|
|
The script to rerun the calculation is
|
|
|
|
`build/utils/update.php --calculate-postcodes`
|
|
|
|
and runs once per night on nominatim.openstreetmap.org.
|
2019-11-06 18:46:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
## Finding places that share a specific postcode
|
|
|
|
|
|
|
|
In the Nominatim database run
|
|
|
|
|
|
|
|
```sql
|
2019-11-12 01:34:44 +03:00
|
|
|
SELECT address->'postcode' as pc,
|
|
|
|
osm_type, osm_id, class, type,
|
|
|
|
st_x(centroid) as lon, st_y(centroid) as lat
|
2019-11-07 00:34:43 +03:00
|
|
|
FROM placex
|
|
|
|
WHERE country_code='fr'
|
|
|
|
AND upper(trim (both ' ' from address->'postcode')) = '33210';
|
2019-11-06 18:46:40 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively on [Overpass](https://overpass-turbo.eu/) run the following query
|
|
|
|
|
|
|
|
```
|
|
|
|
[out:json][timeout:250];
|
|
|
|
area["name"="France"]->.boundaryarea;
|
|
|
|
(
|
|
|
|
nwr(area.boundaryarea)["addr:postcode"="33210"];
|
|
|
|
);
|
|
|
|
out body;
|
|
|
|
>;
|
|
|
|
out skel qt;
|
|
|
|
```
|