58 bokeh
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
# !pip install bokeh jupyter_bokeh
# !pip install bokeh jupyter_bokeh
In [3]:
Copied!
import leafmap.bokehmap as leafmap
import leafmap.bokehmap as leafmap
Create an interactive map
Specify center and zoom level
In [5]:
Copied!
m = leafmap.Map(center=[40, -100], zoom=4, height=400)
m
m = leafmap.Map(center=[40, -100], zoom=4, height=400)
m
Out[5]:
<leafmap.bokehmap.Map at 0x7fa1d1828dd0>
Add basemaps
In [6]:
Copied!
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
Out[6]:
<leafmap.bokehmap.Map at 0x7fa1d16d3350>
In [7]:
Copied!
# print(leafmap.basemaps.keys())
# print(leafmap.basemaps.keys())
Add COG
In [8]:
Copied!
m = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif"
m.add_cog_layer(url)
m
m = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif"
m.add_cog_layer(url)
m
Out[8]:
<leafmap.bokehmap.Map at 0x7fa1d1752e10>
Add STAC
In [9]:
Copied!
m = leafmap.Map()
url = "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json"
m.add_stac_layer(url, bands=["B3", "B2", "B1"], name="False color")
m
m = leafmap.Map()
url = "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json"
m.add_stac_layer(url, bands=["B3", "B2", "B1"], name="False color")
m
Out[9]:
<leafmap.bokehmap.Map at 0x7fa218282c90>
Add local raster datasets
In [10]:
Copied!
url = "https://open.gishub.org/data/raster/srtm90.tif"
leafmap.download_file(url, "dem.tif")
url = "https://open.gishub.org/data/raster/srtm90.tif"
leafmap.download_file(url, "dem.tif")
dem.tif already exists. Skip downloading. Set overwrite=True to overwrite.
Out[10]:
'/home/runner/work/leafmap/leafmap/docs/notebooks/dem.tif'
In [11]:
Copied!
m = leafmap.Map()
m.add_raster("dem.tif", colormap="terrain")
m
m = leafmap.Map()
m.add_raster("dem.tif", colormap="terrain")
m
Out[11]:
<leafmap.bokehmap.Map at 0x7fa1d0d485d0>
Add points
In [12]:
Copied!
m = leafmap.Map()
url = "https://github.com/opengeos/leafmap/blob/master/examples/data/us_cities.geojson"
m.add_geojson(url, size=10, color="blue", alpha=0.7)
m
m = leafmap.Map()
url = "https://github.com/opengeos/leafmap/blob/master/examples/data/us_cities.geojson"
m.add_geojson(url, size=10, color="blue", alpha=0.7)
m
BokehDeprecationWarning: 'circle() method with size value' was deprecated in Bokeh 3.4.0 and will be removed, use 'scatter(size=...) instead' instead.
Out[12]:
<leafmap.bokehmap.Map at 0x7fa1caf6eb10>
Add lines
In [13]:
Copied!
m = leafmap.Map()
m.add_basemap("CartoDB.DarkMatter")
url = "https://github.com/opengeos/leafmap/raw/master/examples/data/cable_geo.geojson"
m.add_vector(url, line_color="color", line_width=2)
m
m = leafmap.Map()
m.add_basemap("CartoDB.DarkMatter")
url = "https://github.com/opengeos/leafmap/raw/master/examples/data/cable_geo.geojson"
m.add_vector(url, line_color="color", line_width=2)
m
Out[13]:
<leafmap.bokehmap.Map at 0x7fa1c1c79010>
Add polygons
In [14]:
Copied!
m = leafmap.Map()
url = "https://github.com/opengeos/leafmap/blob/master/examples/data/countries.geojson"
m.add_vector(url, fill_alpha=0.5, fill_color="lightblue")
m
m = leafmap.Map()
url = "https://github.com/opengeos/leafmap/blob/master/examples/data/countries.geojson"
m.add_vector(url, fill_alpha=0.5, fill_color="lightblue")
m
Out[14]:
<leafmap.bokehmap.Map at 0x7fa1c1c943d0>