]> git.openstreetmap.org Git - nominatim.git/commitdiff
change distance computation between place and address part
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 21 Apr 2022 19:56:59 +0000 (21:56 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 22 Apr 2022 12:32:09 +0000 (14:32 +0200)
Instead of computing the distance to the centroid of the area
compute the distance of the area to the centroid of the feature.
This means we give preference to the area that covers the centroid.
It's still a heuristics but one that is a bit less random.

lib-sql/functions/partition-functions.sql
lib-sql/functions/placex_triggers.sql
lib-sql/functions/postcode_triggers.sql

index cf83f840ebe6b275b021d3f2c746100fcf3df4b4..5eb1aef1e95c535a3160a8252b20c4c1c5c28fb9 100644 (file)
@@ -39,7 +39,10 @@ BEGIN
 END
 $$ LANGUAGE plpgsql IMMUTABLE;
 
-create or replace function getNearFeatures(in_partition INTEGER, feature GEOMETRY, maxrank INTEGER) RETURNS setof nearfeaturecentr AS $$
+CREATE OR REPLACE function getNearFeatures(in_partition INTEGER, feature GEOMETRY,
+                                           feature_centroid GEOMETRY,
+                                           maxrank INTEGER)
+RETURNS setof nearfeaturecentr AS $$
 DECLARE
   r nearfeaturecentr%rowtype;
 BEGIN
@@ -48,7 +51,7 @@ BEGIN
   IF in_partition = {{ partition }} THEN
     FOR r IN
       SELECT place_id, keywords, rank_address, rank_search,
-             min(ST_Distance(feature, centroid)) as distance,
+             min(ST_Distance(feature_centroid, geometry)) as distance,
              isguess, postcode, centroid
       FROM location_area_large_{{ partition }}
       WHERE geometry && feature
index 9463bb27a8ed4e50f04cfcc4850ba7b830936fe4..8a65c555b7553dda42671abb20002f229f331f69 100644 (file)
@@ -449,6 +449,7 @@ CREATE OR REPLACE FUNCTION insert_addresslines(obj_place_id BIGINT,
                                                maxrank SMALLINT,
                                                token_info JSONB,
                                                geometry GEOMETRY,
+                                               centroid GEOMETRY,
                                                country TEXT,
                                                OUT parent_place_id BIGINT,
                                                OUT postcode TEXT,
@@ -511,7 +512,7 @@ BEGIN
   END LOOP;
 
   FOR location IN
-    SELECT * FROM getNearFeatures(partition, geometry, maxrank)
+    SELECT * FROM getNearFeatures(partition, geometry, centroid, maxrank)
     WHERE not addr_place_ids @> ARRAY[place_id]
     ORDER BY rank_address, isguess asc,
              distance *
@@ -1106,7 +1107,8 @@ BEGIN
   END IF;
 
   SELECT * FROM insert_addresslines(NEW.place_id, NEW.partition, max_rank,
-                                    NEW.token_info, geom, NEW.country_code)
+                                    NEW.token_info, geom, NEW.centroid,
+                                    NEW.country_code)
     INTO NEW.parent_place_id, NEW.postcode, nameaddress_vector;
 
   {% if debug %}RAISE WARNING 'RETURN insert_addresslines: %, %, %', NEW.parent_place_id, NEW.postcode, nameaddress_vector;{% endif %}
index f6d81a88089b59098fa96b4bb46dffa282c689eb..3465e775cea5d1e49747cddd5c9856ba91785948 100644 (file)
@@ -34,7 +34,7 @@ BEGIN
     NEW.parent_place_id = 0;
     FOR location IN
       SELECT place_id
-        FROM getNearFeatures(partition, NEW.geometry, NEW.rank_search)
+        FROM getNearFeatures(partition, NEW.geometry, NEW.geometry, NEW.rank_search)
         WHERE NOT isguess ORDER BY rank_address DESC, distance asc LIMIT 1
     LOOP
         NEW.parent_place_id = location.place_id;