From 9cfef7a31a2115dc18f3acef24b61b75f83e9ae2 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 26 Nov 2025 17:44:47 +0100 Subject: [PATCH] prefer wikidata over name match when linking --- lib-sql/functions/placex_triggers.sql | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib-sql/functions/placex_triggers.sql b/lib-sql/functions/placex_triggers.sql index a26fda7f..0494257e 100644 --- a/lib-sql/functions/placex_triggers.sql +++ b/lib-sql/functions/placex_triggers.sql @@ -341,6 +341,22 @@ BEGIN END IF; END IF; + IF bnd.extratags ? 'wikidata' THEN + FOR linked_placex IN + SELECT * FROM placex + WHERE placex.class = 'place' AND placex.osm_type = 'N' + AND placex.extratags ? 'wikidata' -- needed to select right index + AND placex.extratags->'wikidata' = bnd.extratags->'wikidata' + AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id) + AND placex.rank_search < 26 + AND _st_covers(bnd.geometry, placex.geometry) + ORDER BY lower(name->'name') = bnd_name desc + LOOP + {% if debug %}RAISE WARNING 'Found wikidata-matching place node %', linked_placex.osm_id;{% endif %} + RETURN linked_placex; + END LOOP; + END IF; + -- If extratags has a place tag, look for linked nodes by their place type. -- Area and node still have to have the same name. IF bnd.extratags ? 'place' and bnd.extratags->'place' != 'postcode' @@ -361,22 +377,6 @@ BEGIN END LOOP; END IF; - IF bnd.extratags ? 'wikidata' THEN - FOR linked_placex IN - SELECT * FROM placex - WHERE placex.class = 'place' AND placex.osm_type = 'N' - AND placex.extratags ? 'wikidata' -- needed to select right index - AND placex.extratags->'wikidata' = bnd.extratags->'wikidata' - AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id) - AND placex.rank_search < 26 - AND _st_covers(bnd.geometry, placex.geometry) - ORDER BY lower(name->'name') = bnd_name desc - LOOP - {% if debug %}RAISE WARNING 'Found wikidata-matching place node %', linked_placex.osm_id;{% endif %} - RETURN linked_placex; - END LOOP; - END IF; - -- Name searches can be done for ways as well as relations IF bnd_name is not null THEN {% if debug %}RAISE WARNING 'Looking for nodes with matching names';{% endif %} -- 2.39.5