29 pydeck
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import leafmap.deck as leafmap
import leafmap.deck as leafmap
Create an interactive map.
In [3]:
Copied!
m = leafmap.Map(center=(40, -100), zoom=3)
m
m = leafmap.Map(center=(40, -100), zoom=3)
m
Out[3]:
Add basemap.
In [4]:
Copied!
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
Out[4]:
Add vector data to the map. It supports any GeoPandas supported format, such as GeoJSON, shapefile, KML.
In [5]:
Copied!
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
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
Out[5]:
Add a GeoPandas GeoDataFrame to the map.
In [6]:
Copied!
import geopandas as gpd
import geopandas as gpd
In [7]:
Copied!
url = (
"https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_counties.geojson"
)
gdf = gpd.read_file(url)
url = (
"https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_counties.geojson"
)
gdf = gpd.read_file(url)
In [8]:
Copied!
m = leafmap.Map()
m.add_gdf(gdf, random_color_column="STATEFP")
m
m = leafmap.Map()
m.add_gdf(gdf, random_color_column="STATEFP")
m
Out[8]:
Create a 3D view of the map. Press Ctrl and hold down the left mouse button to rotate the 3D view.
In [9]:
Copied!
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
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
Out[9]:
In [10]:
Copied!
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
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
Out[10]:
In [11]:
Copied!
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
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
Out[11]: