Rendering non-default language in OSM-Carto standard map
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
토론
2018년 5월 19일 10:05에 Chetan_Gowda님의 의견
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.
2018년 5월 19일 11:16에 naveenpf님의 의견
Good to see this. !!! Please see the page osm.wiki/Map_internationalization_(India)
2018년 5월 19일 11:38에 Zverik님의 의견
Or you can find “name” in mss styles and replace these with COALESCE(tags->’name:ta’, name). Although it might be a difficult process.
2018년 5월 20일 08:19에 demonshreder님의 의견
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 - osm.wiki/Names#Localization - that a lua script should be enough so went through this process.
2018년 5월 20일 16:42에 cosmobird님의 의견
good to see localized map. kudos.
2018년 5월 21일 02:05에 PlaneMad님의 의견
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.
2018년 5월 21일 03:28에 jocobi님의 의견
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
2018년 5월 21일 03:30에 jocobi님의 의견
Please help me it’s part of my diploma ‘s project
2018년 5월 23일 07:26에 demonshreder님의 의견
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.
2018년 6월 16일 14:33에 Ghybu님의 의견
@ demonshreder
Hello, I have some questions that I can not really find clear answers, maybe you could help me.
Thanks!
2018년 6월 16일 18:49에 demonshreder님의 의견
@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).
2018년 6월 16일 21:08에 Ghybu님의 의견
@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.