From 1b788bfe68247a1669e51e9770805c6482042d2c Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Wed, 14 May 2014 21:54:00 -0700 Subject: [PATCH 1/6] Combine the two medium place layers Previously we had one place layer for capitals and one for non-capitals when it came to towns and cities. This combines them, reducing the number of queries, making the SQL simpler, and making the layers more useful for other styles. Incidentially fixes #522 --- placenames.mss | 28 +++++++++++++++------------- project.mml | 25 +------------------------ 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/placenames.mss b/placenames.mss index d98f2b96c3..c6940680e3 100644 --- a/placenames.mss +++ b/placenames.mss @@ -31,19 +31,21 @@ } } -#placenames-capital { - [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; +#placenames-medium::capital { + [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; + } } } } diff --git a/project.mml b/project.mml index 7082f69d30..ec222cbae5 100644 --- a/project.mml +++ b/project.mml @@ -1114,30 +1114,7 @@ ], "Datasource": { "type": "postgis", - "table": "(select way,place,name,ref\n from planet_osm_point\n where place in ('city','town') and capital='yes'\n ) as placenames_capital", - "extent": "-20037508,-19929239,20037508,19929239", - "key_field": "", - "geometry_field": "way", - "dbname": "gis" - }, - "id": "placenames-capital", - "class": "", - "srs-name": "900913", - "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", - "advanced": {}, - "name": "placenames-capital" - }, - { - "geometry": "point", - "extent": [ - -179.99999692067183, - -84.96651228427099, - 179.99999692067183, - 84.96651228427098 - ], - "Datasource": { - "type": "postgis", - "table": "(select way,place,name\n from planet_osm_point\n where place in ('city','town')\n and (capital is null or capital != 'yes')\n ) as placenames_medium", + "table": "(SELECT way,place,capital,name\n FROM planet_osm_point\n WHERE place IN ('city','town')) AS placenames_medium", "extent": "-20037508,-19929239,20037508,19929239", "key_field": "", "geometry_field": "way", From 98e712a09ecb7e4a3502ca5c7e6ff3a636472c62 Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Thu, 15 May 2014 02:51:52 -0700 Subject: [PATCH 2/6] Get city and town names for both place points and place polygons This is part of #103, but only fixes it for place=city/town The SQL is moderately complex and difficult to document in the .mml file so it's worth documenting here ```sql (SELECT way,place,name,capital,population 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 ``` The ordering merits further discussion We're currently not considering area or population for ordering, so anything is an improvement here. It's hard to say if area,population or population,area is better without trying one first. --- project.mml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.mml b/project.mml index ec222cbae5..7593c23c0e 100644 --- a/project.mml +++ b/project.mml @@ -1114,7 +1114,7 @@ ], "Datasource": { "type": "postgis", - "table": "(SELECT way,place,capital,name\n FROM planet_osm_point\n WHERE place IN ('city','town')) AS placenames_medium", + "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' AND length(population)<10 THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS placenames_medium", "extent": "-20037508,-19929239,20037508,19929239", "key_field": "", "geometry_field": "way", From 5fb24407a2568c067720dac7fec2bb6e7e945de1 Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Thu, 15 May 2014 21:14:36 -0700 Subject: [PATCH 3/6] Combine multiple layers into less top-level MSS --- placenames.mss | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/placenames.mss b/placenames.mss index c6940680e3..bfda3ef978 100644 --- a/placenames.mss +++ b/placenames.mss @@ -31,7 +31,7 @@ } } -#placenames-medium::capital { +#placenames-medium { [capital = 'yes'] { [zoom >= 5][zoom < 15] { text-name: "[name]"; @@ -48,9 +48,7 @@ } } } -} -#placenames-medium::city { [place = 'city'] { [zoom >= 6][zoom < 15] { text-name: "[name]"; @@ -67,9 +65,7 @@ } } } -} -#placenames-medium::town { [place = 'town'] { [zoom >= 9] { text-name: "[name]"; From 048048e8482b8e66f7cd5aa7c36f5174d09f2078 Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Thu, 15 May 2014 23:30:32 -0700 Subject: [PATCH 4/6] Remove a duplicate population length check --- project.mml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.mml b/project.mml index 7593c23c0e..7c154d3eed 100644 --- a/project.mml +++ b/project.mml @@ -1114,7 +1114,7 @@ ], "Datasource": { "type": "postgis", - "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' AND length(population)<10 THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS placenames_medium", + "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS placenames_medium", "extent": "-20037508,-19929239,20037508,19929239", "key_field": "", "geometry_field": "way", From 255b7c740a8d53565b603ead9e1850844d57bb1d Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Thu, 15 May 2014 23:32:16 -0700 Subject: [PATCH 5/6] Give placenames-medium a better name --- placenames.mss | 2 +- project.mml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/placenames.mss b/placenames.mss index bfda3ef978..86a790357c 100644 --- a/placenames.mss +++ b/placenames.mss @@ -31,7 +31,7 @@ } } -#placenames-medium { +#place-medium { [capital = 'yes'] { [zoom >= 5][zoom < 15] { text-name: "[name]"; diff --git a/project.mml b/project.mml index 7c154d3eed..83bc20a461 100644 --- a/project.mml +++ b/project.mml @@ -1114,18 +1114,18 @@ ], "Datasource": { "type": "postgis", - "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS placenames_medium", + "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS place_medium", "extent": "-20037508,-19929239,20037508,19929239", "key_field": "", "geometry_field": "way", "dbname": "gis" }, - "id": "placenames-medium", + "id": "place-medium", "class": "", "srs-name": "900913", "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", "advanced": {}, - "name": "placenames-medium" + "name": "place-medium" }, { "geometry": "point", From 3228744ea6618617f3a471cd6d7f35f8e824ff37 Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Sun, 18 May 2014 23:16:32 -0700 Subject: [PATCH 6/6] Use \d+ and length Benchmarking shows \d+ and length with no NULL check is the fastest way to check if the population is safe to cast --- project.mml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.mml b/project.mml index 83bc20a461..230cbd9648 100644 --- a/project.mml +++ b/project.mml @@ -1114,7 +1114,7 @@ ], "Datasource": { "type": "postgis", - "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS place_medium", + "table": "(SELECT way,place,name,capital,population\n FROM\n (SELECT \n way,place,name,NULL AS capital,way_area,\n CASE WHEN population~E'^\\d+$' AND length(population)<10 THEN population::integer ELSE NULL END AS population\n FROM planet_osm_polygon\n UNION ALL\n SELECT \n way,place,name,capital,NULL AS way_area,\n CASE WHEN population~E'^\\d+$' AND length(population)<10 THEN population::integer ELSE NULL END AS population \n FROM planet_osm_point) AS p\n WHERE place IN ('city','town')\n ORDER BY \n CASE place WHEN 'city' THEN 0 ELSE 10 END,\n CASE capital WHEN 'yes' THEN 0 ELSE 10 END, \n way_area DESC NULLS LAST, \n population DESC NULLS LAST\n) AS place_medium", "extent": "-20037508,-19929239,20037508,19929239", "key_field": "", "geometry_field": "way",