Skip to content

Commit

Permalink
SQL tweaks to improve Mapnik 3 performance for admin areas
Browse files Browse the repository at this point in the history
Admin areas are labeled on the edges, so those where the bbox lies
completely inside can be discarded in SQL.
  • Loading branch information
pnorman committed Jul 1, 2015
1 parent d3e46ab commit 9109ca1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
"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",
"Datasource": {
"extent": "-20037508,-20037508,20037508,20037508",
"table": "(SELECT\n way,\n admin_level\n FROM planet_osm_roads\n WHERE boundary = 'administrative'\n AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')\n ORDER BY admin_level::integer DESC -- With 10 as a valid value, we need to do a numeric ordering, not a text ordering\n) AS admin_high_zoom",
"table": "(SELECT\n way,\n admin_level\n FROM planet_osm_roads\n WHERE boundary = 'administrative'\n AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')\n AND NOT ST_Within(!bbox!, way)\n ORDER BY admin_level::integer DESC -- With 10 as a valid value, we need to do a numeric ordering, not a text ordering\n) AS admin_high_zoom",
"geometry_field": "way",
"type": "postgis",
"key_field": "",
Expand Down Expand Up @@ -1901,7 +1901,7 @@
"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",
"Datasource": {
"extent": "-20037508,-20037508,20037508,20037508",
"table": "(SELECT\n way,\n name,\n admin_level\n FROM planet_osm_polygon\n WHERE boundary = 'administrative'\n AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')\n AND name IS NOT NULL\n ORDER BY admin_level::integer ASC, way_area DESC\n) AS admin_text",
"table": "(SELECT\n way,\n name,\n admin_level\n FROM planet_osm_polygon\n WHERE boundary = 'administrative'\n AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')\n AND name IS NOT NULL\n AND NOT ST_Within(!bbox!, way)\n ORDER BY admin_level::integer ASC, way_area DESC\n) AS admin_text",
"geometry_field": "way",
"type": "postgis",
"key_field": "",
Expand All @@ -1927,7 +1927,7 @@
"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",
"Datasource": {
"extent": "-20037508,-20037508,20037508,20037508",
"table": "(SELECT\n way,\n name,\n way_area/NULLIF(!pixel_width!::real*!pixel_height!::real,0) AS way_pixels\n FROM planet_osm_polygon\n WHERE (boundary = 'national_park' OR leisure = 'nature_reserve')\n AND name IS NOT NULL\n) AS nature_reserve_text",
"table": "(SELECT\n way,\n name,\n way_area/NULLIF(!pixel_width!::real*!pixel_height!::real,0) AS way_pixels\n FROM planet_osm_polygon\n WHERE (boundary = 'national_park' OR leisure = 'nature_reserve')\n AND name IS NOT NULL\n AND NOT ST_Within(!bbox!, way)\n) AS nature_reserve_text",
"geometry_field": "way",
"type": "postgis",
"key_field": "",
Expand Down
3 changes: 3 additions & 0 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ Layer:
FROM planet_osm_roads
WHERE boundary = 'administrative'
AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')
AND NOT ST_Within(!bbox!, way)
ORDER BY admin_level::integer DESC -- With 10 as a valid value, we need to do a numeric ordering, not a text ordering
) AS admin_high_zoom
properties:
Expand Down Expand Up @@ -2134,6 +2135,7 @@ Layer:
WHERE boundary = 'administrative'
AND admin_level IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')
AND name IS NOT NULL
AND NOT ST_Within(!bbox!, way)
ORDER BY admin_level::integer ASC, way_area DESC
) AS admin_text
properties:
Expand All @@ -2154,6 +2156,7 @@ Layer:
FROM planet_osm_polygon
WHERE (boundary = 'national_park' OR leisure = 'nature_reserve')
AND name IS NOT NULL
AND NOT ST_Within(!bbox!, way)
) AS nature_reserve_text
properties:
minzoom: 13
Expand Down

0 comments on commit 9109ca1

Please sign in to comment.