Skip to content

Instantly share code, notes, and snippets.

@pnorman
Created May 16, 2014 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnorman/475075d60ba93a37b86f to your computer and use it in GitHub Desktop.
Save pnorman/475075d60ba93a37b86f to your computer and use it in GitHub Desktop.
#placenames-medium {
[capital = 'yes'] {
[zoom >= 5][zoom < 15] {
text-name: "[name]";
text-size: 10;
text-fill: @placenames;
text-face-name: @book-fonts;
text-halo-radius: 1.5;
text-min-distance: 10;
[zoom >= 6] {
text-size: 12;
}
[zoom >= 11] {
text-size: 15;
}
}
}
[place = 'city'] {
[zoom >= 6][zoom < 15] {
text-name: "[name]";
text-size: 9;
text-fill: @placenames;
text-face-name: @book-fonts;
text-halo-radius: 1.5;
text-min-distance: 10;
[zoom >= 9] {
text-size: 12;
}
[zoom >= 11] {
text-size: 15;
}
}
}
[place = 'town'] {
[zoom >= 9] {
text-name: "[name]";
text-size: 9;
text-fill: @placenames;
text-face-name: @book-fonts;
text-halo-radius: 1.5;
text-wrap-width: 20;
text-min-distance: 10;
}
[zoom >= 11] {
text-size: 11;
}
[zoom >= 14] {
text-size: 15;
text-fill: @placenames-light;
}
}
}
SELECT place,name,capital,population FROM (SELECT way,place,name,capital,population,way_area
FROM
(SELECT
way,place,name,NULL AS capital,way_area, -- The polygon table doesn't have the capital information with the default style
CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population
-- We need to filter out population values that might cause exceptions. This is a fairly rigerous filtering as it will remove population=1,000
FROM planet_osm_polygon
UNION ALL -- Join the two together
SELECT
way,place,name,capital,NULL AS way_area, -- Points don't have an area
CASE WHEN population~E'^\\d{1,9}$' AND length(population)<10 THEN population::integer ELSE NULL END AS population -- as above
FROM planet_osm_point) AS p
WHERE place IN ('city','town') -- This condition is brought inside by the query optimizer
ORDER BY
CASE place WHEN 'city' THEN 0 ELSE 10 END, -- We don't actually need this at moment with the current MSS
CASE capital WHEN 'yes' THEN 0 ELSE 10 END, -- Nor this
way_area DESC NULLS LAST, -- Put physically larger first
population DESC NULLS LAST -- For points (no area) put larger population first
) AS placenames_medium WHERE "way" && ST_SetSRID('BOX3D(-13932330.01959565 6105178.323193599,-12993071.8160274 7044436.526761843)'::box3d, 900913)
┌───────┬──────────────────────────────┬─────────┬────────────┐
│ place │ name │ capital │ population │
├───────┼──────────────────────────────┼─────────┼────────────┤
│ city │ Sumas │ ¤ │ ¤ │
│ city │ Vancouver │ ¤ │ 2100000 │
│ city │ Surrey │ ¤ │ 400000 │
│ city │ Victoria │ 4 │ 330088 │
│ city │ Kamloops │ ¤ │ 85678 │
│ city │ New Westminster │ ¤ │ 58000 │
│ city │ Whistler │ ¤ │ 11000 │
│ city │ Revelstoke │ ¤ │ ¤ │
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment