From: Sarah Hoffmann Date: Mon, 6 Jun 2022 21:44:51 +0000 (+0200) Subject: only add well-formatted postcodes to location table X-Git-Tag: v4.1.0~22^2~13 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/b5e5efc131a29a46a4c5d57f02f7c6b50126f86f only add well-formatted postcodes to location table --- diff --git a/nominatim/tools/postcodes.py b/nominatim/tools/postcodes.py index 42f54cea..dad1edff 100644 --- a/nominatim/tools/postcodes.py +++ b/nominatim/tools/postcodes.py @@ -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)