openmaptiles/layers/aerodrome_label/aerodrome_label.sql
Brian Sperlongano 6ef138635d
Fix negative feature IDs (#1185)
This PR removes the possibility of negative feature IDs for the `aerodrome_label` layer by defining the feature as the absolute value of the OSM id (imposm maps relations with negative numbers).  There is a very unlikely  scenario in which a relation and a way have the same ID (and are also in the same tile), however, unique IDs are not a strict requirement of MVT.

Noted in:
https://github.com/openmaptiles/openmaptiles/pull/1176#issuecomment-902503655

Positive feature ID for Quonset State Airport, which is mapped as a relation:
![image](https://user-images.githubusercontent.com/3254090/130232322-c797d491-ece9-4889-9695-ffb6f3ac011f.png)
2021-08-20 16:40:02 +02:00

44 lines
1.4 KiB
PL/PgSQL

-- etldoc: layer_aerodrome_label[shape=record fillcolor=lightpink, style="rounded,filled", label="layer_aerodrome_label | <z10_> z10+" ] ;
CREATE OR REPLACE FUNCTION layer_aerodrome_label(bbox geometry,
zoom_level integer)
RETURNS TABLE
(
id bigint,
geometry geometry,
name text,
name_en text,
name_de text,
tags hstore,
class text,
iata text,
icao text,
ele int,
ele_ft int
)
AS
$$
SELECT
-- etldoc: osm_aerodrome_label_point -> layer_aerodrome_label:z10_
ABS(osm_id) AS id, -- mvt feature IDs can't be negative
geometry,
name,
COALESCE(NULLIF(name_en, ''), name) AS name_en,
COALESCE(NULLIF(name_de, ''), name, name_en) AS name_de,
tags,
CASE
%%FIELD_MAPPING: class %%
ELSE 'other'
END AS class,
NULLIF(iata, '') AS iata,
NULLIF(icao, '') AS icao,
substring(ele FROM E'^(-?\\d+)(\\D|$)')::int AS ele,
round(substring(ele FROM E'^(-?\\d+)(\\D|$)')::int * 3.2808399)::int AS ele_ft
FROM osm_aerodrome_label_point
WHERE geometry && bbox
AND zoom_level >= 10;
$$ LANGUAGE SQL STABLE
-- STRICT
PARALLEL SAFE;