summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
403e6f7)
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.
END
$$ LANGUAGE plpgsql IMMUTABLE;
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
DECLARE
r nearfeaturecentr%rowtype;
BEGIN
IF in_partition = {{ partition }} THEN
FOR r IN
SELECT place_id, keywords, rank_address, rank_search,
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
isguess, postcode, centroid
FROM location_area_large_{{ partition }}
WHERE geometry && feature
maxrank SMALLINT,
token_info JSONB,
geometry GEOMETRY,
maxrank SMALLINT,
token_info JSONB,
geometry GEOMETRY,
country TEXT,
OUT parent_place_id BIGINT,
OUT postcode TEXT,
country TEXT,
OUT parent_place_id BIGINT,
OUT postcode TEXT,
END LOOP;
FOR location IN
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 *
WHERE not addr_place_ids @> ARRAY[place_id]
ORDER BY rank_address, isguess asc,
distance *
END IF;
SELECT * FROM insert_addresslines(NEW.place_id, NEW.partition, max_rank,
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 %}
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 %}
NEW.parent_place_id = 0;
FOR location IN
SELECT place_id
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;
WHERE NOT isguess ORDER BY rank_address DESC, distance asc LIMIT 1
LOOP
NEW.parent_place_id = location.place_id;