stirringhalo 373a28e7ad Add building heights (#56)
* Add better support for 3d buildings

Change key from "levels" to "building:levels" as the "levels" key is non-standard and sees much less use than "building:levels"

* Fix typo in sql definition and missing render_min_height

* Add render_height and min_height to building.yaml

* Simplify the render, switch numeric to int.

Assume min_height cannot be negative. There are a few examples in overpass, but can't show below ground anyways in mapbox (https://github.com/mapbox/mapbox-gl-js/issues/3456). Also don't attempt to fix min_height>height

* Remove colour as it is not currently used
2016-11-26 20:26:27 +01:00

24 lines
1.1 KiB
PL/PgSQL

-- etldoc: layer_building[shape=record fillcolor=lightpink, style="rounded,filled",
-- etldoc: label="layer_building | <z13> z13 | <z14_> z14_ " ] ;
CREATE OR REPLACE FUNCTION layer_building(bbox geometry, zoom_level int)
RETURNS TABLE(geom geometry, osm_id bigint, render_height int, render_min_height int) AS $$
SELECT geometry, osm_id,
greatest(5, COALESCE(height, levels*3.66,5))::int AS render_height,
greatest(0, COALESCE(min_height, min_level*3.66,0))::int AS render_min_height
FROM (
-- etldoc: osm_building_polygon_gen1 -> layer_building:z13
SELECT osm_id, geometry, height, levels, min_height, min_level FROM osm_building_polygon_gen1
WHERE zoom_level = 13 AND geometry && bbox AND area > 1400
UNION ALL
-- etldoc: osm_building_polygon -> layer_building:z14_
SELECT osm_id, geometry, height, levels, min_height, min_level FROM osm_building_polygon
WHERE zoom_level >= 14 AND geometry && bbox
) AS zoom_levels
ORDER BY render_height ASC, ST_YMin(geometry) DESC;
$$ LANGUAGE SQL IMMUTABLE;