geemap/plotlymap.py
def add_gdf(
        self,
        gdf,
        label_col=None,
        color_col=None,
        labels=None,
        opacity=1.0,
        zoom=None,
        color_continuous_scale="Viridis",
        **kwargs,
    ):
        """Adds a GeoDataFrame to the map.

        Args:
            gdf (GeoDataFrame): A GeoDataFrame.
            label_col (str, optional): The column name of locations. Defaults to None.
            color_col (str, optional): The column name of color. Defaults to None.
        """

        check_package("geopandas", "https://geopandas.org")
        import geopandas as gpd

        if isinstance(gdf, str):
            gdf = gpd.read_file(gdf)

        if not isinstance(gdf, gpd.GeoDataFrame):
            raise ValueError("gdf must be a GeoDataFrame.")

        gdf = gdf.to_crs(epsg=4326)
        # geom_type = gdf_geom_type(gdf)
        center_lon, center_lat = gdf_centroid(gdf)

        if isinstance(label_col, str):
            gdf = gdf.set_index(label_col)
            if label_col == color_col:
                gdf[label_col] = gdf.index
            label_col = gdf.index
        elif label_col is None:
            label_col = gdf.index

        if isinstance(color_col, str):
            if color_col not in gdf.columns:
                raise ValueError(
                    f"color must be a column name in the GeoDataFrame. Can be one of {','.join(gdf.columns)} "
                )
        fig = px.choropleth_mapbox(
            gdf,
            geojson=gdf.geometry,
            locations=label_col,
            color=color_col,
            color_continuous_scale=color_continuous_scale,
            opacity=opacity,
            labels=labels,
            # mapbox_style="carto-positron",
            **kwargs,
        )

        self.add_traces(fig.data)
        self.set_center(center_lat, center_lon, zoom)
Adds a GeoDataFrame to the map.

        Args:
            gdf (GeoDataFrame): A GeoDataFrame.
            label_col (str, optional): The column name of locations. Defaults to None.
            color_col (str, optional): The column name of color. Defaults to None.
        
Adds a GeoDataFrame to the map.
Adds a GeoDataFrame to the map .
def add_gdf(
        self,
        gdf,
        label_col=None,
        color_col=None,
        labels=None,
        opacity=1.0,
        zoom=None,
        color_continuous_scale="Viridis",
        **kwargs,
    ):
        check_package("geopandas", "https://geopandas.org")
        import geopandas as gpd
        if isinstance(gdf, str):
            gdf = gpd.read_file(gdf)
        if not isinstance(gdf, gpd.GeoDataFrame):
            raise ValueError("gdf must be a GeoDataFrame.")
        gdf = gdf.to_crs(epsg=4326)
        center_lon, center_lat = gdf_centroid(gdf)
        if isinstance(label_col, str):
            gdf = gdf.set_index(label_col)
            if label_col == color_col:
                gdf[label_col] = gdf.index
            label_col = gdf.index
        elif label_col is None:
            label_col = gdf.index
        if isinstance(color_col, str):
            if color_col not in gdf.columns:
                raise ValueError(
                    f"color must be a column name in the GeoDataFrame. Can be one of {','.join(gdf.columns)} "
                )
        fig = px.choropleth_mapbox(
            gdf,
            geojson=gdf.geometry,
            locations=label_col,
            color=color_col,
            color_continuous_scale=color_continuous_scale,
            opacity=opacity,
            labels=labels,
            **kwargs,
        )
        self.add_traces(fig.data)
        self.set_center(center_lat, center_lon, zoom)
def add_gdf ( self , gdf , label_col = None , color_col = None , labels = None , opacity = 1.0 , zoom = None , color_continuous_scale = "Viridis" , ** kwargs , ) : check_package ( "geopandas" , "https://geopandas.org" ) import geopandas as gpd if isinstance ( gdf , str ) : gdf = gpd . read_file ( gdf ) if not isinstance ( gdf , gpd . GeoDataFrame ) : raise ValueError ( "gdf must be a GeoDataFrame." ) gdf = gdf . to_crs ( epsg = 4326 ) center_lon , center_lat = gdf_centroid ( gdf ) if isinstance ( label_col , str ) : gdf = gdf . set_index ( label_col ) if label_col == color_col : gdf [ label_col ] = gdf . index label_col = gdf . index elif label_col is None : label_col = gdf . index if isinstance ( color_col , str ) : if color_col not in gdf . columns : raise ValueError ( f"color must be a column name in the GeoDataFrame. Can be one of {','.join(gdf.columns)} " ) fig = px . choropleth_mapbox ( gdf , geojson = gdf . geometry , locations = label_col , color = color_col , color_continuous_scale = color_continuous_scale , opacity = opacity , labels = labels , ** kwargs , ) self . add_traces ( fig . data ) self . set_center ( center_lat , center_lon , zoom )
Adds a GeoDataFrame to the map.
Adds a GeoDataFrame to the map .
"""Adds a GeoDataFrame to the map.

        Args:
            gdf (GeoDataFrame): A GeoDataFrame.
            label_col (str, optional): The column name of locations. Defaults to None.
            color_col (str, optional): The column name of color. Defaults to None.
        """ # geom_type = gdf_geom_type(gdf) # mapbox_style="carto-positron",
self
gdf
None
label_col
The column name of locations. Defaults to None.
The column name of locations . Defaults to None .
None
color_col
The column name of color. Defaults to None.
The column name of color . Defaults to None .
None
labels
opacity
zoom
color_continuous_scale