OpenStreetMap

Rendering non-default language in OSM-Carto standard map

Posted by demonshreder on 19 May 2018 in English (English)

Rendering non-default language in OSM-Carto standard map

Chennai in Tamil

Introduction

OpenStreetMap's standard map rendered in OSMCarto style use only the name tag, for good reasons but what happens when you want to create raster maps in a language of your choice? How do we use the name:xx tags?

Problem

India's map is in English but it officially recognizes 22 languages for its culturally and lingually diverse states including English, Tamil, Malayalam etc.

How do I render OSM Standard map in my mother tongue - Tamil?

Apparently it is just an if statement of three lines in the right place.

Solution

The only hack AFAIK is to change the name tag before data is dumped into postgresql, to do that we need to sideload a lua script to osm2pgsql during the dump using the --tag-transform-script parameters, documentation for it is available here.

The documentation states that the following three methods should be implemented in the tag transformation lua script to filter out specific information from the source .pbf or .osm.xml

  • filter_tags_node
  • filter_tags_way
  • filter_basic_tags_rel

These are the three functions osm2pgsql calls on every tag it adds to the Postgresql database, therefore we would have to implement the same functions in our script.

function filter_tags_node(tags, num_tags)
   if tags["name:ta"] then
    tags["name"] = tags["name:ta"]
   end
return 1, tags
end

So we are checking if the current node has the tag name:ta and if it does, we are replacing its name tag with the Tamil name.

We have to repeat this with the other two functions to change everything into Tamil or language of your choice.

This makes sure that the default name for all data in the rendering database is in Tamil if available.

Making it actually work

This alone isn't enough to render the OSM standard tiles in Tamil. As mentioned in switch2osm we already use openstreetmap-carto's lua script to filter out tags.

osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/tamil_nadu-latest.osm.pbf

Therefore, it would be better at add our code to openstreetmap-carto.lua, something like

function filter_tags_node (keyvalues, numberofkeys)
  if keyvalues["name:ta"] then
    keyvalues["name"] = keyvalues["name:ta"]
  end
  return filter_tags_generic(keyvalues)
end

Remember to repeat for all three methods mentioned in the earlier section.

Resources

Following the steps on switch2osm was enough to create a rendering setup.

https://switch2osm.org/manually-building-a-tile-server-18-04-lts/

I found state wise .pbf extracts for India on OSM-fr

http://download.openstreetmap.fr/extracts/asia/india/

mod_tile renders new tiles only when it is requested, therefore if you want to prerender all tiles, this can be helpful, though selective rendering has been a hit or miss for me.

http://www.volkerschatz.com/net/osm/offlineosm.html

More images can be found here https://imgur.com/gallery/MZmiKsP

Comment from Chetan_Gowda on 19 May 2018 at 10:05

Thanks for sharing on how to render Indic languages in a different approach on default carto style. Would like to try it for Kannada language.

Comment from Zverik on 19 May 2018 at 11:38

Or you can find "name" in mss styles and replace these with COALESCE(tags->'name:ta', name). Although it might be a difficult process.

Comment from demonshreder on 20 May 2018 at 08:19

Personally I dunno the viability of OSMCarto for multiple Indic maps as I feel they are resource intensive. I would like to prerender them as a whole and provide them on a server but I am missing something with render_list. This is where something like vector maps (on openstreetmap.in) help.

@Chetan_Gowda

Please do and share.

@naveenpf

I saw the Wikimedia maps earlier but I wasn't able to find further resources on them but now I have read your diary page on it, I will look into it more.

@Zverik

I see, I was looking into that but read at - https://wiki.openstreetmap.org/wiki/Names#Localization - that a lua script should be enough so went through this process.

Comment from aimomap on 20 May 2018 at 16:42

good to see localized map. kudos.

Comment from PlaneMad on 21 May 2018 at 02:05

Wonderful to see maps in Tamil! Even the city and local government don't have maps in the local languages, and they would be really excited to see this.

Comment from jocobi on 21 May 2018 at 03:28

Hi can someone help me how I can select and show data from geoserver when I clic in point of the map (vector ,raster ) layer

Comment from jocobi on 21 May 2018 at 03:30

Please help me it's part of my diploma 's project

Comment from demonshreder on 23 May 2018 at 07:26

Thanks @aimomap & @PlaneMad

Would be really nice to see localized maps as a part of those smart city projects. Maybe we (community or commercially) could help the local governments achieve that.

Comment from Ghybu on 16 June 2018 at 14:33

@ demonshreder

Hello, I have some questions that I can not really find clear answers, maybe you could help me.

  • Is there a simple way to integrate OSM with the language of your choice in a web page? (It would seem that no)
  • And why OSM does not offer this choice? Is this a technical problems? cost problems? or policy choice?

Thanks!

Comment from demonshreder on 16 June 2018 at 18:49

@Ghybu

For now Wikipedia hosts tiles through https://maps.wikimedia.org/osm-intl/{z} /{x}/{y}@2x.png?lang=${language} URLs. This map doesn't have POIs, it only has streets and their names.

The main reason OSM can't support changing of languages is that, OSM uses raster tiles. It creates images of 256x256 pixels to show the map which means the image can't be changed once it is made, while Wikimedia too uses raster, they only render streets therefore it is very lightweight compared to a full map being rendered. I had to borrow a friend's server with 4 cores and 32GB RAM, it still took about 1.2secs per tile.

Cost is definitely a reason to not offer maps in all languages, beyond that I think OSM is trying to move towards vector maps, which is the right way to approach this issue. I don't have that much experience in serving vector data over the Internet, (VTM is a great library for offline maps on Android).

Comment from Ghybu on 16 June 2018 at 21:08

@demonshreder

Thank you for these explanations. What I find surprising is that OSM offers us the possibility to add local names but not the possibility of visualized them:) What I understand is that OSM is just a database.

Login to leave a comment