At EcoHackNYC last weekend, I spent a lot of time talking with fantastic people about publishing maps from raster data using TileMill. A great post from NASA’s Earth Observatory on a new dataset inspired to make my own visualization of global forest heights, and I wanted to capture the process of working with raster data in TileMill.
Funky blue-to-fusia colors dramatically expose clear patterns of deforestation visible throughout the Amazon near Rodonia.
Raster mapping with open source tools
The high-resolution (1km) data is available for download from the project’s website. You’ll notice that it’s saved as a geotiff, an open [raster]((http://en.wikipedia.org/wiki/GIS_file_formats#Raster) format for geo-referenced images. A variety of open source tools exist for processing raster data. I used QuantumGIS to open the image and start styling. Once colors have been decided, GDAL allows you to burn your new color ramp into your image. After saving, use TileMill to bake your map to mbtiles and upload it to MapBox Hosting.
Picking out colors in QuantumGIS
After selecting the ‘style’ tab in the properties pane, set the Colormap drop down menu to ‘ColorMap’.
Now head over to the ColorMap tab. Set the ‘Number of Entries’ field to 5, and hit classify. This will classify your data five into equal intervals.
QGIS should default to a pretty ridiculous blue-to-red color ramp. You can edit the colors by clicking on them directly, or by specifying a pre-determined ramp from the drop down menu.
Using GDAL to color your raster data
Once you’ve picked out a color ramp you like, it’s time to use GDAL to permanently re-color your image. Grab the RGB values from the color picker, pictured above, and copy them into a .txt file with your favorite text editor. The first column will need to be your data values from qgis, followed by the red, green, and blue values, each separated by a tab. No need for column header. Here’s the ramp I used.
Thanks to Javier and the Vizzuality team for putting on EcoHackNYC. It was great to see so many highly motivated scientists, designers, data analysts, and hardware hackers come together to hack on some of the most compelling new technologies being used to address environmental problems. Among the highlights were csabuilder, a tool to crowdsource interest in Community Supported Agriculture, and new balloons for The Public Laboratory’s balloon mapping kit. One of the most impressive projects was Species Sphere, an interactive visualization of the international trade in wildlife built with CartoDB and d3.js put together in only eight hours. Check out Vizzuality’s blog for a full recap.