def make_colour_scale(self, attr, cmin, cmax, opacity): scale = colour_for_layer(self.defn) def add_class(rgb, expr): rgb *= 255. ###print expr, rgb cls = self.make_class() cls.setExpression(expr) self.outline(cls) style = self.make_style(cls) style.color.setRGB(int(rgb.r), int(rgb.g), int(rgb.b)) style.color.alpha = int(opacity * 255) # below cmin inc = float(cmax - cmin)/(scale.nlevels - 2) add_class(scale.lookup(cmin - inc), "([%s] < %g)" % (attr, cmin)) # intermediate "within range" levels for idx in xrange(1,scale.nlevels-1): vfrom = cmin + (idx - 1) * inc vto = vfrom + inc # we hedge on any floating-point rounding issues with a have increment jump into our level # for the colour lookup add_class(scale.lookup(vfrom+inc/2.), "([%s] >= %g AND [%s] < %g)" % (attr, vfrom, attr, vto)) # above cmin add_class(scale.lookup(cmax + inc), "([%s] >= %g)" % (attr, cmax))
def make_colour_scale(self, attr, cmin, cmax, opacity): scale = colour_for_layer(self.defn) def add_class(rgb, expr): rgb *= 255. cls = self.make_class() cls.setExpression(expr) self.outline(cls) style = self.make_style(cls) style.color.setRGB(int(rgb.r), int(rgb.g), int(rgb.b)) style.color.alpha = int(opacity * 255) # below cmin inc = float(cmax - cmin) / (scale.nlevels - 2) add_class(scale.lookup(cmin - inc), "([%s] < %g)" % (attr, cmin)) # intermediate "within range" levels for idx in xrange(1, scale.nlevels - 1): vfrom = cmin + (idx - 1) * inc vto = vfrom + inc # we hedge on any floating-point rounding issues with a have increment jump into our level # for the colour lookup add_class(scale.lookup(vfrom + inc / 2.), "([%s] >= %g AND [%s] < %g)" % (attr, vfrom, attr, vto)) # above cmin add_class(scale.lookup(cmax + inc), "([%s] >= %g)" % (attr, cmax))
def layer_legend(map_name, layer_id, client_rev): defn_obj = MapDefinition.get_by_name(map_name) if defn_obj is None: abort(404) defn = defn_obj.get() rev = defn.get('rev', 0) if not defn.has_key('layers'): abort(404) layer_defn = defn['layers'].get(layer_id, None) if layer_defn is None: abort(404) scale = colour_for_layer(layer_defn) return Response(headers={'Cache-Control' : 'max-age=86400, public'}, response=scale.legend(), status=200, content_type='image/png')
def layer_legend(map_name, layer_id, client_rev): defn_obj = MapDefinition.get_by_name(map_name) if defn_obj is None: abort(404) defn = defn_obj.get() if 'layers' not in defn: abort(404) layer_defn = defn['layers'].get(layer_id, None) if layer_defn is None: abort(404) scale = colour_for_layer(layer_defn) return Response(headers={'Cache-Control': 'max-age=86400, public'}, response=scale.legend(), status=200, content_type='image/png')