How to use the cartoframes.layer.BaseMap function in cartoframes

To help you get started, we’ve selected a few cartoframes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CartoDB / cartoframes / test / test_layer.py View on Github external
for idx, val in enumerate(dict_colors):
            qlayer = QueryLayer(self.query, color=val)
            self.assertEqual(qlayer.color, dict_colors_ans[idx])
            self.assertEqual(qlayer.scheme, dict_colors_scheme[idx])

        # check valid string color options
        str_colors = ('#FF0000', 'aliceblue', 'cookie_monster', 'big_bird')
        str_colors_ans = ('#FF0000', 'aliceblue', 'cookie_monster', 'big_bird')
        str_scheme_ans = (None, None, styling.mint(5), styling.antique(10))

        for idx, color in enumerate(str_colors):
            qlayer = QueryLayer(self.query, color=color)
            qlayer.geom_type = 'point'
            if color == 'cookie_monster':
                qlayer.style_cols[color] = 'number'
                qlayer._setup([BaseMap(), qlayer], 1)  # pylint: disable=protected-access
            elif color == 'big_bird':
                qlayer.style_cols[color] = 'string'
                qlayer._setup([BaseMap(), qlayer], 1)  # pylint: disable=protected-access
            self.assertEqual(qlayer.color, str_colors_ans[idx])
            self.assertEqual(qlayer.scheme, str_scheme_ans[idx])

        with self.assertRaises(ValueError,
                               msg='styling value cannot be a date'):
            qlayer = QueryLayer(self.query, color='datetime_column')
            qlayer.style_cols['datetime_column'] = 'date'
            qlayer._setup([BaseMap(), qlayer], 1)  # pylint: disable=protected-access

        # Exception testing
        # color column cannot be a geometry column
        with self.assertRaises(ValueError,
                               msg='color clumn cannot be a geometry column'):
github CartoDB / cartoframes / test / test_maps.py View on Github external
def setUp(self):
        self.layers = [BaseMap('dark'),
                       Layer('cb_2013_puma10_500k',
                             color='grey'),
                       Layer('tweets_obama',
                             color='yellow',
                             size='favoritescount')]

        self.layers_w_time = [BaseMap('dark', labels='front'),
                              Layer('acadia'),
                              QueryLayer('select * from acadia limit 10',
                                         time='foo'),
                              Layer('biodiversity'),
                              BaseMap('dark',
                                      labels='front',
                                      only_labels=True)]
github CartoDB / cartoframes / test / test_layer.py View on Github external
def test_layer_setup_dataframe(self):
        """layer.Layer._setup()"""
        layer = Layer('cortado', source=self.coffee_temps)

        with self.assertRaises(NotImplementedError):
            layer._setup([BaseMap(), layer], 1)  # pylint: disable=protected-access
github CartoDB / cartoframes / test / test_layer.py View on Github external
def setUp(self):
        # basemaps with baked-in labels
        self.dark_map_all = BaseMap(source='dark')
        self.light_map_all = BaseMap(source='light')
        self.voyager_labels_under = BaseMap(source='voyager')

        # basemaps with no labels
        self.dark_map_no_labels = BaseMap(source='dark',
                                          labels=None)
        self.light_map_no_labels = BaseMap(source='light',
                                           labels=None)
        self.voyager_map_no_labels = BaseMap(source='voyager',
                                             labels=None)

        # labels with no basemaps
        self.dark_only_labels = BaseMap(source='dark',
                                        only_labels=True)
        self.light_only_labels = BaseMap(source='light',
                                         only_labels=True)
        self.voyager_only_labels = BaseMap(source='voyager',
                                           only_labels=True)
github CartoDB / cartoframes / test / test_layer.py View on Github external
def setUp(self):
        # basemaps with baked-in labels
        self.dark_map_all = BaseMap(source='dark')
        self.light_map_all = BaseMap(source='light')
        self.voyager_labels_under = BaseMap(source='voyager')

        # basemaps with no labels
        self.dark_map_no_labels = BaseMap(source='dark',
                                          labels=None)
        self.light_map_no_labels = BaseMap(source='light',
                                           labels=None)
        self.voyager_map_no_labels = BaseMap(source='voyager',
                                             labels=None)

        # labels with no basemaps
        self.dark_only_labels = BaseMap(source='dark',
                                        only_labels=True)
        self.light_only_labels = BaseMap(source='light',
                                         only_labels=True)
        self.voyager_only_labels = BaseMap(source='voyager',
                                           only_labels=True)
github CartoDB / cartoframes / test / test_layer.py View on Github external
def test_querylayer_time_numeric(self):
        """layer.QueryLayer time with quantitative classification"""
        querylayer = QueryLayer(self.query,
                                time='timecol',
                                color='colorcol')
        # category type
        querylayer.style_cols['colorcol'] = 'number'
        querylayer.style_cols['timecol'] = 'date'
        querylayer.geom_type = 'point'

        # normal behavior for point geometries
        querylayer._setup([BaseMap(), querylayer], 1)  # pylint: disable=protected-access
        self.assertDictEqual(querylayer.scheme,
                             styling.mint(5))
        # expect category maps query
        self.assertRegexpMatches(querylayer.query.strip(),
                                 r'^SELECT \*, colorcol as value '
                                 r'.*_wrap$')
        # cartocss should have cdb math mode
        self.assertRegexpMatches(querylayer.cartocss,
                                 r'.*avg\(colorcol\).*')
github CartoDB / cartoframes / test / test_layer.py View on Github external
def test_basemap_invalid(self):
        """layer.Basemap exceptions on invalid source"""
        # Raise ValueError if invalid label is entered
        with self.assertRaises(ValueError):
            BaseMap(labels='watermelon')

        # Raise ValueError if custom URL is entered
        with self.assertRaises(ValueError):
            BaseMap(source='http://spinalmap.com/{z}/{x}/{y}.png')

        # Raise ValueError if non-supported style type is entered
        with self.assertRaises(ValueError):
            BaseMap(source='gulab_jamon')
github CartoDB / cartoframes / cartoframes / context.py View on Github external
if len(base_layers) > 1:
            raise ValueError('Map can at most take one BaseMap layer')
        elif len(base_layers) == 1:
            layers.insert(0, layers.pop(base_layers[0]))
            if layers[0].is_basic() and layers[0].labels == 'front':
                if time_layers:
                    warn('Basemap labels on top are not currently supported '
                         'for animated maps')
                else:
                    layers.append(BaseMap(layers[0].source,
                                          labels=layers[0].labels,
                                          only_labels=True))
        elif not base_layers:
            # default basemap is dark with labels in back
            # labels will be changed if all geoms are non-point
            layers.insert(0, BaseMap())
            geoms = set()

        # Setup layers
        for idx, layer in enumerate(layers):
            if not layer.is_basemap:
                # get schema of style columns
                resp = self.sql_client.send('''
                    SELECT {cols}
                    FROM ({query}) AS _wrap
                    LIMIT 0
                '''.format(cols=','.join(layer.style_cols),
                           comma=',' if layer.style_cols else '',
                           query=layer.query))
                self._debug_print(layer_fields=resp)
                for k, v in dict_items(resp['fields']):
                    layer.style_cols[k] = v['type']
github CartoDB / cartoframes / cartoframes / context.py View on Github external
layers.append(layers.pop(time_layers[0]))

        base_layers = [idx for idx, layer in enumerate(layers)
                       if layer.is_basemap]

        # Check basemaps, add one if none exist
        if len(base_layers) > 1:
            raise ValueError('Map can at most take one BaseMap layer')
        elif len(base_layers) == 1:
            layers.insert(0, layers.pop(base_layers[0]))
            if layers[0].is_basic() and layers[0].labels == 'front':
                if time_layers:
                    warn('Basemap labels on top are not currently supported '
                         'for animated maps')
                else:
                    layers.append(BaseMap(layers[0].source,
                                          labels=layers[0].labels,
                                          only_labels=True))
        elif not base_layers:
            # default basemap is dark with labels in back
            # labels will be changed if all geoms are non-point
            layers.insert(0, BaseMap())
            geoms = set()

        # Setup layers
        for idx, layer in enumerate(layers):
            if not layer.is_basemap:
                # get schema of style columns
                resp = self.sql_client.send('''
                    SELECT {cols}
                    FROM ({query}) AS _wrap
                    LIMIT 0
github CartoDB / cartoframes / cartoframes / context.py View on Github external
'''.format(cols=','.join(layer.style_cols),
                           comma=',' if layer.style_cols else '',
                           query=layer.query))
                self._debug_print(layer_fields=resp)
                for k, v in dict_items(resp['fields']):
                    layer.style_cols[k] = v['type']
                layer.geom_type = self._geom_type(layer)
                if not base_layers:
                    geoms.add(layer.geom_type)
                # update local style schema to help build proper defaults
            layer._setup(layers, idx)

        # set labels on top if there are no point geometries and a basemap
        #  is not specified
        if not base_layers and 'point' not in geoms:
            layers[0] = BaseMap(labels='front')

        # If basemap labels are on front, add labels layer
        basemap = layers[0]
        if basemap.is_basic() and basemap.labels == 'front':
            layers.append(BaseMap(basemap.source,
                                  labels=basemap.labels,
                                  only_labels=True))

        nb_layers = non_basemap_layers(layers)
        if time_layer and len(nb_layers) > 1:
            raise ValueError('Maps with a time element can only consist of a '
                             'time layer and a basemap. This constraint will '
                             'be removed in the future.')
        options = {'basemap_url': basemap.url}

        for idx, layer in enumerate(nb_layers):