From 373a28e7adabf05ad56cd10155b168c38bb75505 Mon Sep 17 00:00:00 2001 From: stirringhalo Date: Sat, 26 Nov 2016 14:26:27 -0500 Subject: [PATCH] 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 --- layers/building/building.sql | 9 +++++---- layers/building/building.yaml | 6 ++++-- layers/building/mapping.yaml | 10 +++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/layers/building/building.sql b/layers/building/building.sql index 9de11ac..f75ea61 100644 --- a/layers/building/building.sql +++ b/layers/building/building.sql @@ -5,17 +5,18 @@ -- etldoc: label="layer_building | z13 | z14_ " ] ; CREATE OR REPLACE FUNCTION layer_building(bbox geometry, zoom_level int) -RETURNS TABLE(geom geometry, osm_id bigint, render_height numeric) AS $$ +RETURNS TABLE(geom geometry, osm_id bigint, render_height int, render_min_height int) AS $$ SELECT geometry, osm_id, - least(greatest(3, COALESCE(height, levels*3.66,5)),400)^.7::int AS render_height + 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 FROM osm_building_polygon_gen1 + 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 FROM osm_building_polygon + 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; diff --git a/layers/building/building.yaml b/layers/building/building.yaml index 2830e23..1238a33 100644 --- a/layers/building/building.yaml +++ b/layers/building/building.yaml @@ -5,10 +5,12 @@ layer: this is welcomed. buffer_size: 4 datasource: - query: (SELECT geom FROM layer_building(!bbox!, z(!scale_denominator!))) AS t + query: (SELECT geom, render_height, render_min_height FROM layer_building(!bbox!, z(!scale_denominator!))) AS t fields: render_height: | - An approximated height from levels and height of building after the method of Paul Norman in [OSM Clear](https://github.com/ClearTables/osm-clear). For future 3D rendering of buildings. + An approximated height from levels and height of the building or building:part after the method of Paul Norman in [OSM Clear](https://github.com/ClearTables/osm-clear). For future 3D rendering of buildings. + render_min_height: | + An approximated height from levels and height of the bottom of the building or building:part after the method of Paul Norman in [OSM Clear](https://github.com/ClearTables/osm-clear). For future 3D rendering of buildings. schema: - ./building.sql datasources: diff --git a/layers/building/mapping.yaml b/layers/building/mapping.yaml index 8974234..31d1bd4 100644 --- a/layers/building/mapping.yaml +++ b/layers/building/mapping.yaml @@ -20,10 +20,18 @@ tables: - name: height key: height type: integer + - name: min_height + key: min_height + type: integer - name: levels - key: levels + key: building:levels + type: integer + - name: min_level + key: building:min_level type: integer mapping: + building:part: + - __any__ building: - __any__ type: polygon