Skip to content

Continuous colormaps - error trying to convert 'continuous' expression code to color value  #56

@sebbelese

Description

@sebbelese

Hi,

I have an issue with the use of programmatically created legends, but I am not sure if this is a bug or a misuse of my part.

First, I create programmatically a grayscale legend:

        legendGrayscale = Legend.objects.filter(title='grayscale').first()
        if legendGrayscale is None:
            LegendEntry.objects.all().delete()
            LegendSemantics.objects.all().delete()
            Legend.objects.all().delete()
            legendGrayscale = Legend.objects.create(title='grayscale', description='White to black continuous')
            fromSemantics = LegendSemantics.objects.create(name='from')
            toSemantics = LegendSemantics.objects.create(name='to')
            continuousSemantics = LegendSemantics.objects.create(name='continuous')
            fromEntry = LegendEntry.objects.create(semantics=fromSemantics, legend=legendGrayscale, expression='from', color='#FFFFFF', code='#FFFFFF')
            toEntry = LegendEntry.objects.create(semantics=toSemantics, legend=legendGrayscale, expression='to', color='#000000', code='#000000')
            continuousEntry = LegendEntry.objects.create(semantics=continuousSemantics, legend=legendGrayscale, expression='continuous', code='True')

But when I try to render tiles, it complains that the colors cannot be converted from hex to rgb. This is due to the colormap function in models.py where it tries to convert the color associated with the continuous expression to a rgb color:

    @property
    def colormap(self):
        legend = json.loads(self.json)
        cmap = {}
        for leg in legend:
            cmap[leg['expression']] = hex_to_rgba(leg['color'])
        return cmap

My workaround was to update the colormap function, but I am not sure if this was the actual issue, or if my legend was not correctly created.

    @property
    def colormap(self):
        legend = json.loads(self.json)
        cmap = {}
        for leg in legend:
            if leg['expression'] == 'continuous':
                cmap[leg['expression']] = leg['code']
            else:
                cmap[leg['expression']] = hex_to_rgba(leg['color'])
        return cmap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions