OpenStreetMap – Modifying OpenStreetMap-Carto Style to Preference English Labels

mapnikopenstreetmap

I have a working local OSM tile renderer (courtesy the kind people at switch2osm for the instructions). I'd like it to render labels in English where available, falling back to the local name if there is no English. I don't want to show both, or a translation / transliteration.

I'm using the openstreetmap-carto style from git://github.com/gravitystorm/openstreetmap-carto.git

After making sure the rendering works, I've modified the style (based on some guidance on the OSM discussion forums), with this change:

diff --git a/project.mml b/project.mml
index 7fb3d472..2d5099a7 100644
--- a/project.mml
+++ b/project.mml
@@ -90,7 +90,7 @@ Layer:
             way, name, religion, way_pixels, is_building,
             COALESCE(aeroway, golf, amenity, wetland, power, landuse, leisure, man_made, "natural", shop, tourism, highway, railway) AS feature
           FROM (SELECT
-              way, COALESCE(name, '') AS name,
+              way, COALESCE(tags->'name:en', name) AS name,
               ('aeroway_' || (CASE WHEN aeroway IN ('apron', 'aerodrome') THEN aeroway END)) AS aeroway,
               ('golf_' || (CASE WHEN (tags->'golf') IN ('rough', 'fairway', 'driving_range', 'water_hazard', 'green', 'bunker', 'tee') THEN tags->'golf' ELSE NULL END)) AS golf,
               ('amenity_' || (CASE WHEN amenity IN ('bicycle_parking', 'motorcycle_parking', 'university', 'college', 'school', 'taxi',

I've regenerated mapnik.xml, and checked it has a corresponding change. I've checked I have the hstore tags entries in my database.

However even after forcing regeneration of tiles and clearing browser cache, I still see the name value rather than the name:en value. For example, I see "Soomaaliya الصومال" rather than "Somalia".

Can anyone suggest the required changes to render the English name for this style?

Failing that, changes for a similar style would be almost as useful.

Best Answer

You would have to use the COALESCE function every time a name is requested in the sql of the project.mml.

E.g. for country_names (see https://github.com/gravitystorm/openstreetmap-carto/blob/master/project.mml#L1195-L1216 ):

  - id: country-names
geometry: point
<<: *extents
Datasource:
  <<: *osm2pgsql
  table: |-
    (SELECT
        ST_PointOnSurface(way) AS way,
        way_area/NULLIF(POW(!scale_denominator!*0.001*0.28,2),0) AS way_pixels,
        COALESCE(tags->'name:en', name) AS name
      FROM planet_osm_polygon
      WHERE ST_PointOnSurface(way) && !bbox!
        AND name IS NOT NULL
        AND boundary = 'administrative'
        AND admin_level = '2'
        AND way_area > 100*POW(!scale_denominator!*0.001*0.28,2)
        AND way_area < 4000000*POW(!scale_denominator!*0.001*0.28,2)
        AND osm_id < 0
      ORDER BY way_area DESC
    ) AS country_names
properties:
  minzoom: 2

There are quite a few occurrences where a name is selected, you would have to change all those where you want the English label used (if available).

Related Question