def layer(self, layer_ids=None, request=None):
        """Return a layer with all stickies or stickies with selected
        tags
        """
        start_end = current_start_end_dates(request)
        layers = []
        styles = {}
        layer = mapnik.Layer("Stickies", WGS84)
        layer.datasource = mapnik.MemoryDatasource()
        stickies = self.stickies.exclude(time__gte=start_end[1]
                                         ).filter(time__gte=start_end[0])
        for _id, sticky in enumerate(stickies):
            add_datasource_point(layer.datasource,
                                 sticky.geom.x,
                                 sticky.geom.y,
                                 'Name',
                                 'hssd',
                                 _id)
        # generate "unique" point style name and append to layer
        style_name = "StickyTweets"
        styles[style_name] = self.style()
        layer.styles.append(style_name)

        layers = [layer, ]
        return layers, styles
Example #2
0
    def layer(self, layer_ids=None, webcolor=None, request=None):
        """Return layer and styles that render points.

        """
        layers = []
        styles = {}
        layer = mapnik.Layer("FEWS JDBC points layer", coordinates.WGS84)

        layer.datasource = mapnik.PointDatasource()

        try:
            named_locations = self._locations()
        except FewsJdbcQueryError:
            logger.exception('Problem querying locations from jdbc2ei.')
            return [], {}

        fews_styles, fews_style_lookup = IconStyle._styles_lookup()

        logger.debug("Number of point objects: %d" % len(named_locations))
        for named_location in named_locations:
            #logger.debug('layer coordinates %s %s %s' % (
            #        named_location['locationid'],
            #        named_location['longitude'],
            #        named_location['latitude']))

            point_style_name, point_style = fews_point_style(
                self.jdbc_source,
                self.filterkey,
                named_location['locationid'],
                self.parameterkey,
                nodata=False,
                styles=fews_styles,
                lookup=fews_style_lookup)

            # Put style in point, filters work on these styles.
            add_datasource_point(
                layer.datasource, named_location['longitude'],
                named_location['latitude'], 'style', str(point_style_name))

            # generate "unique" point style name and append to layer
            # if the same style occurs multiple times, it will overwrite old.
            style_name = str("Lizard-FewsJdbc::%s" % (point_style_name))
            styles[style_name] = point_style

        # Add all style names to the layer styles.
        for style_name in styles.keys():
            layer.styles.append(style_name)

        layers = [layer, ]
        return layers, styles
Example #3
0
    def layer(self, layer_ids=None, webcolor=None, request=None):
        logger.debug("In lizard_fancylayers.layer")
        # We only do point layers right now
        if not self.datasource.has_property(properties.LAYER_POINTS):
            logger.debug("Datasource is not a point layer.")
            return [], {}

        layers = []
        styles = {}

        locations = list(self.datasource.locations())
        colors = {"default": html_to_mapnik('0000ff')}
        logger.debug("1")
        for location in locations:
            if location.color is not None:
                colors[location.color] = html_to_mapnik(location.color)

        style = mapnik.Style()
        logger.debug("2")

        for colorname, color in colors.iteritems():
            rule = mapnik.Rule()
            symbol = mapnik.PointSymbolizer(
                symbol_filename(color), 'png', 16, 16)
            symbol.allow_overlap = True
            rule.symbols.append(symbol)
            rule.filter = mapnik.Filter("[Color] = '{0}'".format(colorname))
            style.rules.append(rule)

        styles['trivialStyle'] = style
        logger.debug("3")

        layer = mapnik.Layer("Fancy Layers layer", coordinates.WGS84)
        layer.datasource = mapnik.PointDatasource()
        layer.styles.append('trivialStyle')
        logger.debug("4 - {0}".format(locations))

        for location in locations:
            color = location.color or 'default'
            logger.debug('{0}: {1}'.format(location, color))
            add_datasource_point(
                layer.datasource, location.longitude,
                location.latitude,
                'Color', str(color))
        logger.debug("5")

        layers.append(layer)
        return layers, styles
Example #4
0
    def layer(self, layer_ids=None, request=None):
        "Return Mapnik layers and styles."
        layers, styles = [], {}
        styles["pointsStyle"] = self.style()
        layer = mapnik.Layer("Geodin points layer", coordinates.WGS84)
        layer.datasource = mapnik.PointDatasource()
        layer.styles.append("pointsStyle")

        for point in self.measurement.points.all():
            add_datasource_point(
                layer.datasource,
                point.location.x,
                point.location.y,
                'style',
                'pointsStyle')

        layers.append(layer)
        return layers, styles
Example #5
0
    def layer(self, layer_ids=None, webcolor=None, request=None):
        # We only do point layers right now
        if not self.datasource.has_property(properties.LAYER_POINTS):
            return [], {}

        layers = []
        styles = {}

        locations = list(self.datasource.locations())
        colors = {"default": html_to_mapnik(default_color())}

        for location in locations:
            if location.color is not None:
                colors[location.color] = html_to_mapnik(location.color)

        style = mapnik.Style()

        for colorname, color in colors.iteritems():
            rule = mapnik.Rule()
            symbol = mapnik.PointSymbolizer()
            symbol.filename = symbol_pathname(color)
            symbol.allow_overlap = True
            rule.symbols.append(symbol)
            rule.filter = mapnik.Filter("[Color] = '{0}'".format(colorname))
            style.rules.append(rule)

        styles['trivialStyle'] = style

        layer = mapnik.Layer("Fancy Layers layer", coordinates.WGS84)
        layer.datasource = mapnik.MemoryDatasource()
        layer.styles.append('trivialStyle')

        for _id, location in enumerate(locations):
            color = location.color or 'default'
            add_datasource_point(
                layer.datasource, location.longitude,
                location.latitude,
                'Color', str(color), _id)

        layers.append(layer)
        return layers, styles
    def layer(self, layer_ids=None, request=None):
        """Return a layer with all stickies or stickies with selected
        tags
        """
        start_end = current_start_end_dates(request)
        layers = []
        styles = {}
        layer = mapnik.Layer("Stickies", WGS84)
        layer.datasource = mapnik.MemoryDatasource()
        stickies = self.stickies.exclude(time__gte=start_end[1]).filter(
            time__gte=start_end[0])
        for _id, sticky in enumerate(stickies):
            add_datasource_point(layer.datasource, sticky.geom.x,
                                 sticky.geom.y, 'Name', 'hssd', _id)
        # generate "unique" point style name and append to layer
        style_name = "StickyTweets"
        styles[style_name] = self.style()
        layer.styles.append(style_name)

        layers = [
            layer,
        ]
        return layers, styles
    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