From a7ea07ee0daa9e3ef50d83c45d3bb7eb2e590d48 Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Fri, 12 Mar 2010 13:34:32 +0000 Subject: [PATCH] modified raster_colorizer so the color of the last band is used if the value matches its value exactly. This is to make declaring legends for rasters with discrete values easier (ie: no need to define a dummy band for N+1) --- include/mapnik/raster_colorizer.hpp | 12 ++++++++---- tests/python_tests/raster_colorizer_test.py | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/mapnik/raster_colorizer.hpp b/include/mapnik/raster_colorizer.hpp index af6efcf14..dc76e5eba 100644 --- a/include/mapnik/raster_colorizer.hpp +++ b/include/mapnik/raster_colorizer.hpp @@ -153,9 +153,11 @@ namespace mapnik * if cs[pos].value <= value < cs[pos+1].value: cs[pos].color * otherwise: transparent * where 0 <= pos < length(bands)-1 + * Last band is special, its value represents the upper bound and its + * color will only be used if the value matches its value exactly. */ color get_color(float value) const { - int pos=-1, lo=0, hi=colors_.size()-1; + int pos=-1, last=(int)colors_.size()-1, lo=0, hi=last; while (lo<=hi) { pos = (lo+hi)/2; if (colors_[pos].value_