示例#1
0
    def test_style(self):
        """See if style() output correspond to expected lookup.
        """
        IconStyle(
            fews_filter=None, fews_location=None, fews_parameter=None, icon="icon.png", mask="mask.png", color="ff00ff"
        ).save()
        IconStyle(
            fews_filter=self.filter1,
            fews_location=None,
            fews_parameter=None,
            icon="filter1.png",
            mask="mask.png",
            color="00ffff",
        ).save()
        IconStyle(
            fews_filter=None,
            fews_location=self.location1,
            fews_parameter=None,
            icon="par1.png",
            mask="mask.png",
            color="00ffff",
        ).save()
        IconStyle(
            fews_filter=self.filter1,
            fews_location=self.location1,
            fews_parameter=None,
            icon="loc1.png",
            mask="mask.png",
            color="00ffff",
        ).save()
        IconStyle(
            fews_filter=self.filter1,
            fews_location=self.location1,
            fews_parameter=self.parameter1,
            icon="par1.png",
            mask="mask.png",
            color="00ffff",
        ).save()
        IconStyle(
            fews_filter=None,
            fews_location=self.location1,
            fews_parameter=self.parameter1,
            icon="loc1par1.png",
            mask="mask.png",
            color="00ffff",
        ).save()

        expected1 = ("::::", {"icon": "icon.png", "mask": ("mask.png",), "color": (1.0, 0.0, 1.0, 1.0)})
        self.assertEqual(IconStyle.style(self.filter2, self.location2, self.parameter2), expected1)
        self.assertEqual(IconStyle.style(self.filter2, self.location2, self.parameter2, ignore_cache=True), expected1)
def fews_symbol_name(
    fews_filter_pk, fews_location_pk, fews_parameter_pk,
    nodata=False, styles=None, lookup=None):

    """Find fews symbol name"""

    # determine icon layout by looking at filter.id
    # if str(fews_filter.fews_id) in LAYER_STYLES:
    #     icon_style = copy.deepcopy(LAYER_STYLES[str(fews_filter.fews_id)])
    # else:
    #     icon_style = copy.deepcopy(LAYER_STYLES['default'])
    style_name, icon_style = IconStyle.style(
        fews_filter_pk, fews_location_pk, fews_parameter_pk, styles, lookup)

    #make icon grey
    if nodata:
        icon_style['color'] = (0.9, 0.9, 0.9, 0)

    # apply icon layout using symbol manager
    symbol_manager = SymbolManager(
        ICON_ORIGINALS,
        os.path.join(settings.MEDIA_ROOT, 'generated_icons'))
    output_filename = symbol_manager.get_symbol_transformed(
        icon_style['icon'], **icon_style)

    return style_name, output_filename
示例#3
0
    def test_empty(self):
        """Do not crash when no iconstyles are available, just return default.
        """

        expected = (
            "::::",
            {"icon": "meetpuntPeil.png", "mask": ("meetpuntPeil_mask.png",), "color": (0.0, 0.5, 1.0, 1.0)},
        )

        self.assertEqual(IconStyle.style(self.filter2, self.location1, self.parameter1), expected)
示例#4
0
    def test_lookup(self):
        IconStyle(
            fews_filter=None, fews_location=None, fews_parameter=None, icon="icon.png", mask="mask.png", color="ff00ff"
        ).save()
        IconStyle(
            fews_filter=self.filter1,
            fews_location=None,
            fews_parameter=None,
            icon="filter1.png",
            mask="mask.png",
            color="ff00ff",
        ).save()
        IconStyle(
            fews_filter=None,
            fews_location=self.location1,
            fews_parameter=self.parameter1,
            icon="loc1par1.png",
            mask="mask.png",
            color="00ffff",
        ).save()
        IconStyle(
            fews_filter=None,
            fews_location=self.location1,
            fews_parameter=None,
            icon="loc1.png",
            mask="mask.png",
            color="00ffff",
        ).save()

        expected = {
            # Level0: fews_filter
            None: {
                # Level1: fews_location
                None: {
                    # Level2: fews_parameter
                    None: "::::"
                },
                self.location1.pk: {
                    # Level2: fews_parameter
                    None: "::%d::" % self.location1.pk,
                    self.parameter1.pk: "::%d::%d" % (self.location1.pk, self.parameter1.pk),
                },
            },
            self.filter1.pk: {
                # Level1: fews_location
                None: {
                    # Level2: fews_parameter
                    None: "%d::::"
                    % self.filter1.pk
                }
            },
        }

        self.assertEqual(IconStyle._lookup(), expected)
    def layer(self, layer_ids=None, webcolor=None, request=None):
        """Return layer and styles that render points."""
        layers = []
        styles = {}
        styles_nodata = {}
        styles_data = {}
        layer = mapnik.Layer("FEWS points layer", coordinates.WGS84)
        layer_nodata = mapnik.Layer("FEWS points layer (no data)",
                                    coordinates.WGS84)
        #filterkey = self.filterkey
        #parameterkey = self.parameterkey
        #fews_filter = Filter.objects.get(pk=filterkey)
        #fews_parameter = Parameter.objects.get(pk=parameterkey)

        layer.datasource = mapnik.PointDatasource()
        layer_nodata.datasource = mapnik.PointDatasource()

        fews_styles, fews_style_lookup = IconStyle._styles_lookup()

        for info in self._timeseries():
            # Due to mapnik bug, we render the very same point 10cm to the top
            # right, bottom left, etc.
            add_datasource_point(
                layer.datasource, info['longitude'], info['latitude'],
                'Name', info['location_name'])

            if not info['has_data']:
                add_datasource_point(
                    layer_nodata.datasource,
                    info['longitude'], info['latitude'],
                    'Name', info['location_name'])

            point_style_name, point_style = fews_point_style(
                info['object'].filterkey, info['object'].locationkey,
                info['object'].parameterkey, nodata=False, styles=fews_styles,
                lookup=fews_style_lookup)
            # generate "unique" point style name and append to layer
            style_name = "fews-unblobbed::%s" % point_style_name
            styles_data[style_name] = point_style

            point_style_nodata_name, point_style_nodata = fews_point_style(
                info['object'].filterkey, info['object'].locationkey,
                info['object'].parameterkey, nodata=True, styles=fews_styles,
                lookup=fews_style_lookup)
            # generate "unique" point style name and append to layer
            style_name_nodata = "fews-unblobbed-nodata::%s" % (
                point_style_nodata_name)
            styles[style_name_nodata] = point_style_nodata  # to return
            styles_nodata[style_name_nodata] = point_style_nodata  # for layer

        for style_name in styles_data.keys():
            layer.styles.append(style_name)

        for style_name_nodata in styles_nodata.keys():
            layer_nodata.styles.append(style_name_nodata)

        styles = styles_data
        styles.update(styles_nodata)

        layers = [layer_nodata, layer]  # TODO: the layer WITH data on top
        return layers, styles