Skip to content

29 pydeck

image image image

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap
1
import leafmap.deck as leafmap

Create an interactive map.

1
2
m = leafmap.Map(center=(40, -100), zoom=3)
m

Add basemap.

1
2
3
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m

Add vector data to the map. It supports any GeoPandas supported format, such as GeoJSON, shapefile, KML.

1
2
3
4
5
6
m = leafmap.Map()
filename = (
    "https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_states.geojson"
)
m.add_vector(filename, random_color_column="STATEFP")
m

Add a GeoPandas GeoDataFrame to the map.

1
import geopandas as gpd
1
2
3
4
url = (
    "https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_counties.geojson"
)
gdf = gpd.read_file(url)
1
2
3
m = leafmap.Map()
m.add_gdf(gdf, random_color_column="STATEFP")
m

Create a 3D view of the map. Press Ctrl and hold down the left mouse button to rotate the 3D view.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
initial_view_state = {
    "latitude": 40,
    "longitude": -100,
    "zoom": 3,
    "pitch": 45,
    "bearing": 10,
}
m = leafmap.Map(initial_view_state=initial_view_state)
filename = (
    "https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_states.geojson"
)
m.add_vector(
    filename,
    random_color_column="STATEFP",
    extruded=True,
    get_elevation="ALAND",
    elevation_scale=0.000001,
)
m

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
m = leafmap.Map(center=(40, -100), zoom=3)
DATA_URL = "https://data.source.coop/cboettig/conservation-policy/Inflation_Reduction_Act_Projects.geojson"
gdf = gpd.read_file(DATA_URL)

m.add_vector(
    gdf,
    layer_type="ColumnLayer",
    get_position=["LONGITUDE", "LATITUDE"],
    get_elevation="FUNDING_NUMERIC",
    get_fill_color=[256, 256, 0, 140],
    elevation_scale=0.01,
    radius=10000,
    pickable=True,
    auto_highlight=True,
)
m
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import pydeck as pdk

m = leafmap.Map(center=(40, -100), zoom=3)

DATA_URL = "https://data.source.coop/cboettig/conservation-policy/Inflation_Reduction_Act_Projects.geojson"
df = gpd.read_file(DATA_URL)

column_layer = pdk.Layer(
    "ColumnLayer",
    data=df,
    get_position=["LONGITUDE", "LATITUDE"],
    get_elevation="FUNDING_NUMERIC",
    get_fill_color=[256, 256, 0, 140],
    elevation_scale=0.01,
    radius=10000,
    pickable=True,
    auto_highlight=True,
)

m.add_layer(column_layer)
m