Refactor place layer

This commit is contained in:
lukasmartinelli
2016-10-28 12:05:18 +02:00
parent 52c7306563
commit 38dcc030b0
5 changed files with 52 additions and 119 deletions

29
layers/place/city.sql Normal file
View File

@@ -0,0 +1,29 @@
CREATE OR REPLACE FUNCTION layer_city(bbox geometry, zoom_level int, pixel_width numeric)
RETURNS TABLE(osm_id bigint, geometry geometry, name text, name_en text, place text, scalerank int) AS $$
SELECT osm_id, geometry, name, name_en, place, scalerank
FROM osm_important_place_point
WHERE geometry && bbox
AND ((zoom_level = 2 AND scalerank = 0)
OR (zoom_level BETWEEN 3 AND 7 AND scalerank < zoom_level)
)
UNION ALL
SELECT osm_id, geometry, name, name_en, place, NULL AS scalerank FROM (
SELECT osm_id, geometry, name, name_en, place,
row_number() OVER (
PARTITION BY LabelGrid(geometry, 150 * pixel_width)
ORDER BY place::place_subclass ASC NULLS LAST,
population DESC NULLS LAST,
length(name) DESC
) AS gridrank
FROM osm_place_point
WHERE geometry && bbox
AND ((zoom_level BETWEEN 8 AND 9 AND place::place_subclass <= 'town'::place_subclass)
OR (zoom_level = 10 AND place::place_subclass <= 'village'::place_subclass)
OR (zoom_level BETWEEN 11 AND 13 AND place::place_subclass <= 'suburb'::place_subclass)
OR (zoom_level >= 14)
)
) AS ranked_places
WHERE (zoom_level = 8 AND gridrank <= 4)
OR (zoom_level BETWEEN 9 AND 12 AND gridrank <= 9)
OR (zoom_level >= 13);
$$ LANGUAGE SQL IMMUTABLE;