If you search the internet for ‘alpha to color’ you get lots of results describing how to convert ‘color to alpha’ and its applications.
Here we will be doing the opposite: converting alpha channel to color and demonstrating how it can be useful for visualization.
Colorize-alpha image-filter is the son of the popular colorize-alpha compositing operator by Tom.
We wanted to have more control over which colors are used, and how colors are distributed. To achieve this we moved colorize-alpha to image-filters.
How it works
The new syntax, and an explanation of how this filter is different from the original compositing operation, are best done through a working example.
I use point geometries for this particular example but it can be anything else. The important thing here is that the symbolization should have a variable ‘alpha’ channel to achieve the desired effect. We’ll use a simple ‘marker’ icon with radially distributed alpha channel from $MAPNIK_SRC/tests/data/images/marker.png
(NOTE: I used a modified version of the original image with more transparency and scaled down to 32x32 px).
Colorize-alpha is an image-filter and works at the layer level. Technically, we accumulate alpha channel values from densely positioned markers and convert this value to the color. Simple. The result? A poor-man’s heatmap.
colorize-alpha( <color-stop> [, <color-stop>]+ )
List of color stops (2..N)
where <color-stop> := <color> [ <percentage> | <length> ]?
and <color> is any valid CSS color
As you can see this simple technique can be deployed to achieve interesting visual effects. While ‘hot-spot’ mapping above is the most obvious use-case, I bet there’ll be more awesome looking maps originated from creative usage of this filter.
builds the core infrastructure behind Mapbox's suite of mapping tools. He is the creator of Mapnik, the open source map renderer powering many open source mapping tools including Mapbox Studio and OpenStreetMap.
Follow @mapnik on Twitter