mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
country_name: use separate columns for names from OSM
This allows us to distinguish between base names and imported ones and consiquently removing imported ones if necessary.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
CREATE TABLE public.country_name (
|
CREATE TABLE public.country_name (
|
||||||
country_code character varying(2),
|
country_code character varying(2),
|
||||||
name public.hstore,
|
name public.hstore,
|
||||||
|
derived_name public.hstore,
|
||||||
country_default_language_code text,
|
country_default_language_code text,
|
||||||
partition integer
|
partition integer
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ CREATE OR REPLACE FUNCTION get_addressdata(in_place_id BIGINT, in_housenumber IN
|
|||||||
DECLARE
|
DECLARE
|
||||||
place addressdata_place;
|
place addressdata_place;
|
||||||
location RECORD;
|
location RECORD;
|
||||||
|
country RECORD;
|
||||||
current_rank_address INTEGER;
|
current_rank_address INTEGER;
|
||||||
location_isaddress BOOLEAN;
|
location_isaddress BOOLEAN;
|
||||||
BEGIN
|
BEGIN
|
||||||
@@ -198,6 +199,16 @@ BEGIN
|
|||||||
WHERE place_id = place.place_id
|
WHERE place_id = place.place_id
|
||||||
LOOP
|
LOOP
|
||||||
--RAISE WARNING '%',location;
|
--RAISE WARNING '%',location;
|
||||||
|
-- mix in default names for countries
|
||||||
|
IF location.rank_address = 4 and place.country_code is not NULL THEN
|
||||||
|
FOR country IN
|
||||||
|
SELECT coalesce(name, ''::hstore) as name FROM country_name
|
||||||
|
WHERE country_code = place.country_code LIMIT 1
|
||||||
|
LOOP
|
||||||
|
place.name := country.name || place.name;
|
||||||
|
END LOOP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
IF location.rank_address < 4 THEN
|
IF location.rank_address < 4 THEN
|
||||||
-- no country locations for ranks higher than country
|
-- no country locations for ranks higher than country
|
||||||
place.country_code := NULL::varchar(2);
|
place.country_code := NULL::varchar(2);
|
||||||
@@ -272,7 +283,8 @@ BEGIN
|
|||||||
-- If no country was included yet, add the name information from country_name.
|
-- If no country was included yet, add the name information from country_name.
|
||||||
IF current_rank_address > 4 THEN
|
IF current_rank_address > 4 THEN
|
||||||
FOR location IN
|
FOR location IN
|
||||||
SELECT name FROM country_name WHERE country_code = place.country_code LIMIT 1
|
SELECT name || coalesce(derived_name, ''::hstore) as name FROM country_name
|
||||||
|
WHERE country_code = place.country_code LIMIT 1
|
||||||
LOOP
|
LOOP
|
||||||
--RAISE WARNING '% % %',current_rank_address,searchcountrycode,countryname;
|
--RAISE WARNING '% % %',current_rank_address,searchcountrycode,countryname;
|
||||||
RETURN NEXT ROW(null, null, null, location.name, 'place', 'country', NULL,
|
RETURN NEXT ROW(null, null, null, location.name, 'place', 'country', NULL,
|
||||||
|
|||||||
@@ -117,16 +117,6 @@ BEGIN
|
|||||||
|
|
||||||
-- ---- All other place types.
|
-- ---- All other place types.
|
||||||
|
|
||||||
-- Patch in additional country names
|
|
||||||
IF NEW.admin_level = 2 and NEW.type = 'administrative' and NEW.address ? 'country'
|
|
||||||
THEN
|
|
||||||
FOR country IN
|
|
||||||
SELECT name FROM country_name WHERE country_code = lower(NEW.address->'country')
|
|
||||||
LOOP
|
|
||||||
NEW.name = country.name || NEW.name;
|
|
||||||
END LOOP;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- When an area is changed from large to small: log and discard change
|
-- When an area is changed from large to small: log and discard change
|
||||||
IF existing.geometry is not null AND ST_IsValid(existing.geometry)
|
IF existing.geometry is not null AND ST_IsValid(existing.geometry)
|
||||||
AND ST_Area(existing.geometry) > 0.02
|
AND ST_Area(existing.geometry) > 0.02
|
||||||
|
|||||||
@@ -1044,16 +1044,22 @@ BEGIN
|
|||||||
AND NEW.class = 'boundary' AND NEW.type = 'administrative'
|
AND NEW.class = 'boundary' AND NEW.type = 'administrative'
|
||||||
AND NEW.country_code IS NOT NULL AND NEW.osm_type = 'R'
|
AND NEW.country_code IS NOT NULL AND NEW.osm_type = 'R'
|
||||||
THEN
|
THEN
|
||||||
-- Update the list of country names. Adding an additional sanity
|
-- Update the list of country names.
|
||||||
-- check here: make sure the country does overlap with the area where
|
-- Only take the name from the largest area for the given country code
|
||||||
-- we expect it to be as per static country grid.
|
-- in the hope that this is the authoritive one.
|
||||||
|
-- Also replace any old names so that all mapping mistakes can
|
||||||
|
-- be fixed through regular OSM updates.
|
||||||
FOR location IN
|
FOR location IN
|
||||||
SELECT country_code FROM country_osm_grid
|
SELECT osm_id FROM placex
|
||||||
WHERE ST_Covers(geometry, NEW.centroid) and country_code = NEW.country_code
|
WHERE rank_search = 4 and osm_type = 'R'
|
||||||
|
and country_code = NEW.country_code
|
||||||
|
ORDER BY ST_Area(geometry) desc
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
LOOP
|
LOOP
|
||||||
{% if debug %}RAISE WARNING 'Updating names for country '%' with: %', NEW.country_code, NEW.name;{% endif %}
|
IF location.osm_id = NEW.osm_id THEN
|
||||||
UPDATE country_name SET name = name || NEW.name WHERE country_code = NEW.country_code;
|
{% if debug %}RAISE WARNING 'Updating names for country '%' with: %', NEW.country_code, NEW.name;{% endif %}
|
||||||
|
UPDATE country_name SET derived_name = NEW.name WHERE country_code = NEW.country_code;
|
||||||
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user