83 vector viz
Visualizing large vector datasets with lonboard
This notebook demonstrates how to visualize large vector datasets with lonboard. Please note that lonboard does not support Visual Studio Code's interactive notebook yet. You will need to run this notebook in Jupyter Notebook or JupyterLab.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install -U leafmap lonboard
# %pip install -U leafmap lonboard
In [2]:
Copied!
import leafmap.deckgl as leafmap
import geopandas as gpd
import ipywidgets as widgets
import leafmap.deckgl as leafmap
import geopandas as gpd
import ipywidgets as widgets
Download sample datasets.
In [3]:
Copied!
url = "https://open.gishub.org/data/duckdb/nyc_data.zip"
leafmap.download_file(url, unzip=True)
url = "https://open.gishub.org/data/duckdb/nyc_data.zip"
leafmap.download_file(url, unzip=True)
Downloading... From: https://open.gishub.org/data/duckdb/nyc_data.zip To: /home/runner/work/leafmap/leafmap/docs/notebooks/nyc_data.zip
0%| | 0.00/8.73M [00:00<?, ?B/s]
100%|██████████| 8.73M/8.73M [00:00<00:00, 130MB/s]
Extracting files...
Out[3]:
'/home/runner/work/leafmap/leafmap/docs/notebooks/nyc_data.zip'
Create an interactive map.
In [4]:
Copied!
m = leafmap.Map(center=[20, 0], zoom=1.2)
m
m = leafmap.Map(center=[20, 0], zoom=1.2)
m
Add GeoDataFrame.
In [5]:
Copied!
streets = gpd.read_file("nyc_streets.shp")
m.add_gdf(streets, zoom_to_layer=True, pickable=True, get_width=5)
streets = gpd.read_file("nyc_streets.shp")
m.add_gdf(streets, zoom_to_layer=True, pickable=True, get_width=5)
Add any vector format supported by GeoPandas.
In [6]:
Copied!
m.add_vector("nyc_subway_stations.shp", get_radius=10, get_fill_color=[255, 0, 0, 180])
m.add_vector("nyc_subway_stations.shp", get_radius=10, get_fill_color=[255, 0, 0, 180])
Change layer properties.
In [7]:
Copied!
layer = m.layers[-1]
layer.get_fill_color = [0, 0, 255, 255]
layer = m.layers[-1]
layer.get_fill_color = [0, 0, 255, 255]
Interactive widgets.
In [8]:
Copied!
color = widgets.ColorPicker(value="red", description="Color")
width = widgets.IntSlider(min=1, max=100, value=10, description="Radius")
hbox = widgets.HBox([color, width])
color = widgets.ColorPicker(value="red", description="Color")
width = widgets.IntSlider(min=1, max=100, value=10, description="Radius")
hbox = widgets.HBox([color, width])
In [9]:
Copied!
widgets.dlink((color, "value"), (layer, "get_fill_color"))
widgets.dlink((width, "value"), (layer, "get_radius"))
widgets.dlink((color, "value"), (layer, "get_fill_color"))
widgets.dlink((width, "value"), (layer, "get_radius"))
Out[9]:
<traitlets.traitlets.directional_link at 0x7f8552d96600>
In [10]:
Copied!
hbox
hbox
In [11]:
Copied!
m
m