How we painted road shields on the map

In OsmAnd, we decided to draw a shield as close to reality as possible, using the data from OpenStreetMap.
OpenStreetMap and General Notation
OSM does not have a commonly accepted way to describe road shields. Routes of roads are described using relation (“relations”) of type route = road. But, firstly, they are well made only for countries with developed infrastructure and / or with a strong local OSM community. Secondly, they usually do not contain information about the color and shape of the shield. Therefore, along with OSM data, we used various open sources, including Wikipedia and sites.google.com/site/roadnumberingsystems/home/countries .
The main idea of using the information available in OSM is that we take a road relation and assign the color and shape of the shield, the color of the number (ref), depending on the network tag. Just in case, we limit the scope to a certain region or country. But this only works for a limited set of countries. Also, an approach was often used consisting in parsing ref (road number) and extracting a prefix from it or some sequence inside.

Based on this and the country containing the road, a conclusion is drawn about the characteristics of the road shield. Third method: some countries have a system of designating road numbers by number ranges. For example: from 0 to 99 - regional road, blue shield with white text; 100-499 - national road, green shield with yellow text, etc. Sometimes a combined approach was used. Also, when creating an OsmAnd map, information on shields priorities is written there, depending on the system of designating the road numbers of specific countries.
In the OSM wiki, there is a ref: color tag, which is used in the world only about 5,000 times. Most often it is found in Spain - one of the few countries where none of the above methods for determining the shield parameters work. In this case, the background color is taken directly from this tag.
USA
In the USA, the situation is as follows. Road relations are mapped very well, but shields are defined differently: there are US Interstate highways, US State highways, secondary highways, territorial highways, state highways, county highways, which mainly differ in the number of separators (colons) in the value of the network tag.

The situation is complicated by the fact that almost every state uses its own shields for state highways. Considering their huge number, we decided to draw these shields in a simplified way.




Examples of Road shield from different states: North Dakota, Idaho, Minnesota, Florida.
Many roads have modifiers: spur, truck, business, alternate, etc. In OsmAnd, they are displayed above the shield itself in a small rectangle - the same as on real signs.

Canada
In Canada, each state uses its own road numbering system. The exception is Transcanada Highways, for which the OSM does not adopt a unique tagging method. The problem was completely solved only by adding a check to the name of the road for the content of the text "transcanada" in different variations

Europe

The countries of Europe for the most part do not use curly shield, as, for example, in the USA. Instead, rectangular labels are widely used. The exceptions are Hungary, Romania, the Netherlands (stadsroutes, city roads), motorways in Germany, Greece and Italy. The type of road is indicated by the background color, as well as the text color.
European car routes have the prefix E and from one to three white numbers on a green rectangular background. These routes are to some extent similar to the interregional routes of the United States (Interstate Highways). A sign of such a route in OSM is the relation route = road and the tag network = e-road. During data processing, it turned out that the relations of some of these routes did not contain the network = e-road tag, which was eliminated.

Other countries
There are countries (Lebanon, Mongolia) where it turned out to be difficult to establish what colors and shapes in reality should be shields. It seems that road shields are not used at all in these countries.
Israel, South Korea, Saudi Arabia and some other countries use shields that are not used anywhere else.

The main map style on openstreetmap.org, mapnik, does not use data from road relations. This fact, together with historical reasons, led to the fact that, as a rule, the ref tag is affixed to all participants in these relations. At the same time, a significant part of roads is not included in road relations, and the value of the ref tag is the only data source. Therefore, we cannot drop the ref tag and rely only on road relations. Instead, we, in the absence of an appropriate road relation, will transform the ref tag to that internal data representation that is used to store tags obtained from road relations. This makes it possible to simplify the map style code.
At the time of publication, OsmAnd supports road shields in almost the entire world. The exception is part of Africa and part of Central America.