openmaptiles/layers/transportation_name/highway_classification.sql
Brian Sperlongano 79c2ec929d
Add new layer to serve highway=motorway_junction nodes (#1119)
This PR adds a layer for `highway=motorway_junction` features.

This implementation of highway exits in the transportation_name layer add to the existing layer table structure, and renames the internal column name from "construction" (which was already overloaded with non-construction usages) to "subclass", which will be less confusing to future developers.  The string 'junction' is used as the universal sub-class for highway exits.

A new documentation PR has been opened at openmaptiles/www.openmaptiles.org#69 to reflect these changes in the documentation.
2021-06-28 14:35:27 +02:00

58 lines
1.2 KiB
PL/PgSQL

CREATE OR REPLACE FUNCTION highway_to_val(hwy_class varchar)
RETURNS int
IMMUTABLE
LANGUAGE plpgsql
AS $$
BEGIN
CASE hwy_class
WHEN 'motorway' THEN RETURN 6;
WHEN 'trunk' THEN RETURN 5;
WHEN 'primary' THEN RETURN 4;
WHEN 'secondary' THEN RETURN 3;
WHEN 'tertiary' THEN RETURN 2;
WHEN 'unclassified' THEN RETURN 1;
else RETURN 0;
END CASE;
END;
$$;
CREATE OR REPLACE FUNCTION val_to_highway(hwy_val int)
RETURNS varchar
IMMUTABLE
LANGUAGE plpgsql
AS $$
BEGIN
CASE hwy_val
WHEN 6 THEN RETURN 'motorway';
WHEN 5 THEN RETURN 'trunk';
WHEN 4 THEN RETURN 'primary';
WHEN 3 THEN RETURN 'secondary';
WHEN 2 THEN RETURN 'tertiary';
WHEN 1 THEN RETURN 'unclassified';
else RETURN null;
END CASE;
END;
$$;
CREATE OR REPLACE FUNCTION highest_hwy_sfunc(agg_state varchar, hwy_class varchar)
RETURNS varchar
IMMUTABLE
LANGUAGE plpgsql
AS $$
BEGIN
RETURN val_to_highway(
GREATEST(
highway_to_val(agg_state),
highway_to_val(hwy_class)
)
);
END;
$$;
DROP AGGREGATE IF EXISTS highest_highway (varchar);
CREATE AGGREGATE highest_highway (varchar)
(
sfunc = highest_hwy_sfunc,
stype = varchar
);