diff --git a/data.yml b/data.yml index fab9daa..03d10ae 100644 --- a/data.yml +++ b/data.yml @@ -90,26 +90,13 @@ Layer: max_size: 512 password: osm port: 5432 - srid: '' - table: |- - ( SELECT geom, type - FROM ( - SELECT ST_Simplify(geom, 80000) AS geom, type FROM ice_z0 - WHERE z(!scale_denominator!) BETWEEN 0 AND 1 - UNION ALL - SELECT * FROM ice_z2 - WHERE z(!scale_denominator!) BETWEEN 2 AND 4 - UNION ALL - SELECT * FROM ice_z5 - WHERE z(!scale_denominator!) BETWEEN 5 AND 8 - ) AS ice - WHERE geom && !bbox! - ) AS t + srid: 900913 + table: (SELECT * FROM layer_ice(!bbox!, z(!scale_denominator!))) AS t type: postgis user: osm description: Ice shelves fields: - type: String + class: String properties: "buffer-size": 4 srs: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over diff --git a/schema/layers/ice.sql b/schema/layers/ice.sql index 89d187d..c6e31be 100644 --- a/schema/layers/ice.sql +++ b/schema/layers/ice.sql @@ -15,3 +15,19 @@ CREATE OR REPLACE VIEW ice_z5 AS ( UNION ALL SELECT geom, 'ice_shelf' AS type FROM ne_10m_antarctic_ice_shelves_polys ); + +CREATE OR REPLACE FUNCTION layer_ice(bbox geometry, zoom_level int) +RETURNS TABLE(geom geometry, class text) AS $$ + WITH zoom_levels AS ( + SELECT ST_Simplify(geom, 80000) AS geom, type FROM ice_z0 + WHERE zoom_level BETWEEN 0 AND 1 + UNION ALL + SELECT * FROM ice_z2 + WHERE zoom_level BETWEEN 2 AND 4 + UNION ALL + SELECT * FROM ice_z5 + WHERE zoom_level BETWEEN 5 AND 8 + ) + SELECT geom, type::text AS class FROM zoom_levels + WHERE geom && bbox; +$$ LANGUAGE SQL IMMUTABLE;