2

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.

4
  • 1
    Have you restarted renderd and apache so that renderd is not using an old (internally cached) mapnik.xml but the new one with the changes? Did you do a render_list --force ... for the re-rendering? Is renderd linking the changed mapnik.xml style file correctly? So I would first look at renderds conf and restart renderd and apache to have that style change working.
    – crnm
    May 5, 2022 at 13:12
  • Thanks for the suggestions. I definitely restarted renderd. I also used --force as noted in the question ("after forcing regeneration"). I may or may not have restarted apache though - will try that when I can get back into the lab.
    – BradHards
    May 6, 2022 at 5:48
  • 1
    And another question: did you changed the name coalesce call just once in the project.mml? I would expect more than a dozen changes you would have to do, e.g. the above one you quoted in your diff is not altering the labels for cities or countries or streets, etc.
    – crnm
    May 6, 2022 at 7:55
  • That is the substance of the question - what are the places that need to be changed? How do I identify them? In something like github.com/gravitystorm/openstreetmap-carto/blob/master/… - what is the change?
    – BradHards
    May 6, 2022 at 9:16

1 Answer 1

1
+200

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).

2
  • Thanks. That works for at least some of the labels. I'm still working through testing, but the approach seems sound. I'm not going so well on placename-medium (with the nested select), but assume I can work out something in time.
    – BradHards
    May 9, 2022 at 0:35
  • Now good - rendering fine.
    – BradHards
    May 9, 2022 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.