Skip to content

Commit

Permalink
return fclass_iso, fclass_tlc, and label_x, label_y for OSM features …
Browse files Browse the repository at this point in the history
…with matching NE features (#2082)
  • Loading branch information
tgrigsby-sc committed May 4, 2022
1 parent b05b25d commit b810954
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions data/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,65 @@ BEGIN
END;
$$ LANGUAGE plpgsql STABLE;

CREATE OR REPLACE FUNCTION tz_get_fclass_and_label_position(wikidata_id TEXT, place_tag TEXT)
RETURNS JSONB AS $$
DECLARE
fclass_iso TEXT;
fclass_tlc TEXT;
label_x REAL;
label_y REAL;
BEGIN
IF wikidata_id IS NULL THEN
RETURN '{}'::jsonb;
END IF;

-- if it's a country, only look it up in the iso and tlc tables
IF place_tag='country' OR place_tag='unrecognized' THEN
SELECT
fclass_iso, fclass_tlc, label_x, label_y INTO fclass_iso, fclass_tlc, label_x, label_y
FROM ne_10m_admin_0_countries_iso i
WHERE i.wikidataid = wikidata_id;

IF NOT FOUND THEN
SELECT
fclass_iso, fclass_tlc, label_x, label_y INTO fclass_iso, fclass_tlc, label_x, label_y
FROM ne_10m_admin_0_countries_tlc t
WHERE t.wikidataid = wikidata_id;
END IF;

IF NOT FOUND THEN
RETURN '{}'::jsonb;
END IF;
END IF;

-- There is no label_x and label_y for the non-countries (please confirm @nkelso!)
SELECT
fclass_iso, fclass_tlc, NULL, NULL INTO fclass_iso, fclass_tlc, label_x, label_y
FROM ne_10m_admin_1_states_provinces sp
WHERE sp.wikidataid = wikidata_id;

-- finally, try localities
IF NOT FOUND THEN
SELECT
fclass_iso, fclass_tlc, NULL, NULL INTO fclass_iso, fclass_tlc, label_x, label_y
FROM ne_10m_populated_places pp
WHERE pp.wikidataid = wikidata_id;END IF;

-- return an empty JSONB rather than null, so that it can be safely
-- concatenated with whatever other JSONB rather than needing a check for
-- null.
IF NOT FOUND THEN
RETURN '{}'::jsonb;
END IF;
RETURN jsonb_build_object(
'__ne_fclass_iso', fclass_iso,
'__ne_fclass_tlc', fclass_tlc,
'__ne_label_x', label_x,
'__ne_label_y', label_y
);
END;
$$ LANGUAGE plpgsql STABLE;


-- returns a JSONB object containing __ne_pop_min and __ne_pop_max
CREATE OR REPLACE FUNCTION tz_get_ne_pop_min_max(wikidata_id TEXT)
Expand Down
2 changes: 2 additions & 0 deletions queries/planet_osm_point.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ SELECT
tz_get_ne_min_max_zoom(tags->'wikidata', tags->'place')
||
tz_get_ne_pop_min_max(tags->'wikidata')
||
tz_get_fclass_and_label_position(tags->'wikidata', tags->'place')
END AS __places_properties__,

CASE WHEN mz_poi_min_zoom IS NOT NULL
Expand Down

0 comments on commit b810954

Please sign in to comment.