Mapping
First, we need to import the biospat package and specify the modules to use both Map classes.¶
In [1]:
Copied!
import biospat.mapping as biospat_ipyleaflet
import biospat.foliummap as biospat_foliummap
import biospat.mapping as biospat_ipyleaflet
import biospat.foliummap as biospat_foliummap
Now, let's create a basic and advanced map using ipyleaflet.¶
A simple OpenStreetMap with ipyleaflet¶
In [2]:
Copied!
simple_map = biospat_ipyleaflet.Map(center=[40, -100], zoom=4, height="300px")
simple_map
simple_map = biospat_ipyleaflet.Map(center=[40, -100], zoom=4, height="300px")
simple_map
Out[2]:
In [3]:
Copied!
advanced_map = biospat_ipyleaflet.Map(center=[40, -100], zoom=4, height="300px")
advanced_map.add_basemap("OpenTopoMap")
url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
advanced_map.add_geojson(url, name="Cities")
advanced_map.add_layer_control()
advanced_map
advanced_map = biospat_ipyleaflet.Map(center=[40, -100], zoom=4, height="300px")
advanced_map.add_basemap("OpenTopoMap")
url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
advanced_map.add_geojson(url, name="Cities")
advanced_map.add_layer_control()
advanced_map
Out[3]:
Now let's create a basic and advanced map using Folium¶
A simple OpenStreetMap and OpenTopoMap with Folium that can be toggled.¶
In [4]:
Copied!
simple_folium = biospat_foliummap.Map(center=[20, 0], zoom=2, tiles="OpenStreetMap")
simple_folium.add_basemap("OpenTopoMap")
simple_folium.add_layer_control()
simple_folium
simple_folium = biospat_foliummap.Map(center=[20, 0], zoom=2, tiles="OpenStreetMap")
simple_folium.add_basemap("OpenTopoMap")
simple_folium.add_layer_control()
simple_folium
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
# new_map.add_split_map(left="Esri.WorldImagery", right="cartodbpositron")
# Add a split map with a GeoTIFF on the left and a basemap on the right
new_map = biospat_foliummap.Map(center=[20, 0], zoom=2)
# Add split map with two GeoTIFFs on the left and right
new_map.add_split_map(
left="https://raw.githubusercontent.com/kgjenkins/ophz/master/tif/ophz-us48.tif",
right="https://raw.githubusercontent.com/kgjenkins/ophz/master/tif/ophz-us48.tif",
colormap_left="viridis",
colormap_right="magma",
opacity_left=0.9,
opacity_right=0.8,
)
# Add the LayerControl to toggle layers independently
new_map.add_layer_control()
new_map
# new_map.add_split_map(left="Esri.WorldImagery", right="cartodbpositron")
# Add a split map with a GeoTIFF on the left and a basemap on the right
new_map = biospat_foliummap.Map(center=[20, 0], zoom=2)
# Add split map with two GeoTIFFs on the left and right
new_map.add_split_map(
left="https://raw.githubusercontent.com/kgjenkins/ophz/master/tif/ophz-us48.tif",
right="https://raw.githubusercontent.com/kgjenkins/ophz/master/tif/ophz-us48.tif",
colormap_left="viridis",
colormap_right="magma",
opacity_left=0.9,
opacity_right=0.8,
)
# Add the LayerControl to toggle layers independently
new_map.add_layer_control()
new_map
/home/runner/.local/lib/python3.11/site-packages/rio_tiler/io/rasterio.py:135: NoOverviewWarning: The dataset has no Overviews. rio-tiler performances might be impacted. warnings.warn(
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [6]:
Copied!
advanced_folium = biospat_foliummap.Map(
center=[20, 0], zoom=2, tiles="CartoDB dark_matter"
)
url = "https://github.com/opengeos/datasets/releases/download/world/countries.geojson"
advanced_folium.add_geojson(url, name="Countries")
advanced_folium.add_layer_control()
advanced_folium
advanced_folium = biospat_foliummap.Map(
center=[20, 0], zoom=2, tiles="CartoDB dark_matter"
)
url = "https://github.com/opengeos/datasets/releases/download/world/countries.geojson"
advanced_folium.add_geojson(url, name="Countries")
advanced_folium.add_layer_control()
advanced_folium
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook
We can also add shp data from a URL to a ipyleaflet and Folium map.¶
For example, we can examine the rivers of Australia using ipyleaflet.¶
In [7]:
Copied!
aus_rivers_ipyleaflet = biospat_ipyleaflet.Map(
center=[-25, 135], zoom=4, height="300px"
)
aus_rivers_ipyleaflet.add_shp_from_url(
"https://github.com/nvkelso/natural-earth-vector/blob/master/10m_physical/ne_10m_rivers_australia",
name="Rivers of Australia",
)
aus_rivers_ipyleaflet.add_layer_control()
aus_rivers_ipyleaflet
aus_rivers_ipyleaflet = biospat_ipyleaflet.Map(
center=[-25, 135], zoom=4, height="300px"
)
aus_rivers_ipyleaflet.add_shp_from_url(
"https://github.com/nvkelso/natural-earth-vector/blob/master/10m_physical/ne_10m_rivers_australia",
name="Rivers of Australia",
)
aus_rivers_ipyleaflet.add_layer_control()
aus_rivers_ipyleaflet
Out[7]:
Or, we can examine the major lakes of the world on an ESRI imagery map using Folium.¶
In [8]:
Copied!
world_lakes_folium = biospat_foliummap.Map(
center=[39.8283, -98.5795], zoom=4, tiles="Esri.WorldImagery"
)
world_lakes_folium.add_shp_from_url(
"https://github.com/nvkelso/natural-earth-vector/blob/master/10m_physical/ne_10m_lakes",
name="Lakes of Europe",
)
world_lakes_folium.add_layer_control()
world_lakes_folium
world_lakes_folium = biospat_foliummap.Map(
center=[39.8283, -98.5795], zoom=4, tiles="Esri.WorldImagery"
)
world_lakes_folium.add_shp_from_url(
"https://github.com/nvkelso/natural-earth-vector/blob/master/10m_physical/ne_10m_lakes",
name="Lakes of Europe",
)
world_lakes_folium.add_layer_control()
world_lakes_folium
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook