From 4c06f800558b31071771cafda11c2389b92f883d Mon Sep 17 00:00:00 2001 From: Paul Norman Date: Thu, 21 Jul 2022 18:47:11 -0700 Subject: [PATCH] Improve country label placement by splitting By splitting MPs into polygons, taking the largest, and finding a point in 4326 we get better points for placing labels. 4326 does distort the placement, but it does so in a way that results in better results for most countries. --- project.mml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/project.mml b/project.mml index ab3966e0ae..44579837ff 100644 --- a/project.mml +++ b/project.mml @@ -1178,13 +1178,20 @@ Layer: <<: *extents Datasource: <<: *osm2pgsql + # By splitting MPs into polygons, finding the largest in real area, and + # finding a label point in 4326 we get better labeling points. 4326 does + # distort the placement, but it does so in a way that results in better + # results for most countries. table: |- (SELECT - ST_PointOnSurface(way) AS way, + (SELECT ST_Transform(ST_PointOnSurface(geom),3857) + FROM ST_Dump(ST_Transform(way,4326)) + ORDER BY ST_Area(geom::geography) DESC + LIMIT 1) AS way, way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels, name FROM planet_osm_polygon - WHERE ST_PointOnSurface(way) && !bbox! + WHERE way && !bbox! AND name IS NOT NULL AND boundary = 'administrative' AND admin_level = '2'