]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/tools/postcodes.py
only add well-formatted postcodes to location table
[nominatim.git] / nominatim / tools / postcodes.py
index 42f54cea3ed603034c5ffd456a0668b9860fe82c..dad1edff7f9264b3e9fa5f676545b2f4aa95bfce 100644 (file)
@@ -18,6 +18,7 @@ from psycopg2 import sql as pysql
 
 from nominatim.db.connection import connect
 from nominatim.utils.centroid import PointsCentroid
+from nominatim.data.postcode_format import PostcodeFormatter
 
 LOG = logging.getLogger()
 
@@ -162,6 +163,7 @@ def update_postcodes(dsn, project_dir, tokenizer):
         potentially enhances it with external data and then updates the
         postcodes in the table 'location_postcode'.
     """
+    matcher = PostcodeFormatter()
     with tokenizer.name_analyzer() as analyzer:
         with connect(dsn) as conn:
             # First get the list of countries that currently have postcodes.
@@ -193,7 +195,9 @@ def update_postcodes(dsn, project_dir, tokenizer):
                             collector.commit(conn, analyzer, project_dir)
                         collector = _CountryPostcodesCollector(country)
                         todo_countries.discard(country)
-                    collector.add(postcode, x, y)
+                    match = matcher.match(country, postcode)
+                    if match:
+                        collector.add(matcher.normalize(country, match), x, y)
 
                 if collector is not None:
                     collector.commit(conn, analyzer, project_dir)