As just stated on the Fossgis Hackingweekend at the Linuxhotel in Essen… “I’m mapping the year of constrcution for a (huge) number of houses. I’m looking for a way to visualize this on the map”.
Likely multiple solutions exist, but how to do this with libosmscout?
At the start of the weekend this was not yet possible. Small discussion with another developer (not at the weekend) showed, that a general approach was needed, as colouring of ways based on attributes has also interesting use cases (hint: colour of metro lines).
Libosmscout implements tag and value combinations as features. All possible features of an object type (configurable during import) are flag in a bit set, if an concrete object has the feature.
The value of an feature is implemented as simple class that must offer serialization and deserialization methods.
So first we write a new Feature implementation that parses the
year_of_construction tags. The new Feature will have two int attribute for the start and end year. Investigation of the actual tag values show and creation time can be an time interval, for our needs the year however is enough. Depending on the use case other implementation could be possible, too.
We need to do some string parsing to get most of the possible variants of the tag values parsed. Mapper: Please do not be to creative ;-)
Afterwards we add the possibility to register style processors into the rendering pipeline. The processor has a simple interface. It gets the list of feature values and the style as defined by the style sheet. It returns either the original style or a (cache) new style instance. Processors are registered by type.
Next step is to implement a simple processor for the type
building. The processor checks if the construction year feature is available and the year between 1800 and 2020. In this case it return a red fill style, with the actual brightness depending on the age. Older buildings get darker red.
See the result:
Since there are not that much buildings with construction year mapped, let us try something more visible. Different colors depending on the house number been odd even (or not numerical).
Now that looks more obvious :-)
Fine. That was fun. Now back to code to refactor it for a slightly better API…