Changeset 1686

Show
Ignore:
Timestamp:
03/12/10 08:34:32 (5 months ago)
Author:
alberto
Message:

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)

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/mapnik/raster_colorizer.hpp

    r1685 r1686  
    154154         *   otherwise: transparent 
    155155         *     where 0 <= pos < length(bands)-1 
     156         *   Last band is special, its value represents the upper bound and its 
     157         *   color will only be used if the value matches its value exactly. 
    156158         */ 
    157159         color get_color(float value) const { 
    158             int pos=-1, lo=0, hi=colors_.size()-1; 
     160            int pos=-1, last=(int)colors_.size()-1, lo=0, hi=last; 
    159161            while (lo<=hi) { 
    160162                pos = (lo+hi)/2; 
     
    169171            } 
    170172            lo--; 
    171             return (0 <= lo && lo < (int)colors_.size()-1)? 
    172                 colors_[lo].color_: 
    173                 color(0,0,0,0); 
     173            if ((0 <= lo && lo < last) || 
     174                (lo==last && colors_[last].value_==value)) 
     175                return colors_[lo].color_; 
     176            else 
     177                return color(0,0,0,0); 
    174178         } 
    175179 
  • trunk/tests/python_tests/raster_colorizer_test.py

    r1685 r1686  
    1919        ( 80, "#990099"), 
    2020        ( 90, "#660066"), 
    21         ( 200, "#00000"), # last band denotes upper limit, values above it will 
    22                           # not return the color 
     21        ( 200, "#ffffff"), 
    2322        ]] 
    2423    for value, color in bands: 
     
    2928    eq_(colorizer.get_color(5), bands[0][1]) 
    3029    eq_(colorizer.get_color(10), bands[1][1]) 
    31     eq_(colorizer.get_color(200), mapnik2.Color("transparent")) 
     30    # last value is used if it matches exactly 
     31    eq_(colorizer.get_color(200), bands[-1][1]) 
     32    #  values greater than the last value are mapped to "transparent" 
    3233    eq_(colorizer.get_color(201), mapnik2.Color("transparent"))