01 folium
Testing Custom Folium and Ipyleaflet classes¶
In [1]:
Copied!
#!pip install pypackage_example
#!pip install pypackage_example
In [2]:
Copied!
# import my custom package and modules
import pypackage_example as pl
import pypackage_example.foliumap as flp
# import folium
# import ipyleaflet
# import geopandas as gpd
# import my custom package and modules
import pypackage_example as pl
import pypackage_example.foliumap as flp
# import folium
# import ipyleaflet
# import geopandas as gpd
Testing pypackage_example (built on ipyleaflet)¶
In [3]:
Copied!
m = pl.LeafletMap()
# m.add_basemap2(basemap="Esri.WorldImagery")
m.add_layer_control()
m
m = pl.LeafletMap()
# m.add_basemap2(basemap="Esri.WorldImagery")
m.add_layer_control()
m
Out[3]:
In [4]:
Copied!
# just a list of URLs to try
# url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.geojson"
# url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.gpkg"
# url = 'https://github.com/opengeos/datasets/releases/download/us/us_regions.gpkg'
# url = r"C:\Users\loren\Downloads\us_counties\us_counties.shp" # this won't work because it's in my local machine
# url = r"C:\Users\loren\Desktop\xf_paper\area_bianca_background.gpkg" # this won't work because it's in my local machine
url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.zip"
# just a list of URLs to try
# url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.geojson"
# url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.gpkg"
# url = 'https://github.com/opengeos/datasets/releases/download/us/us_regions.gpkg'
# url = r"C:\Users\loren\Downloads\us_counties\us_counties.shp" # this won't work because it's in my local machine
# url = r"C:\Users\loren\Desktop\xf_paper\area_bianca_background.gpkg" # this won't work because it's in my local machine
url = "https://github.com/opengeos/datasets/releases/download/us/us_southeast.zip"
add vector layer from URL¶
In [5]:
Copied!
m = pl.LeafletMap()
m.add_vector(
url,
name="Countries",
zoom_to_layer=True,
style={"color": "green", "fillOpacity": 0.6},
)
m.add_layer_control()
m
m = pl.LeafletMap()
m.add_vector(
url,
name="Countries",
zoom_to_layer=True,
style={"color": "green", "fillOpacity": 0.6},
)
m.add_layer_control()
m
Out[5]:
add raster layers¶
In [6]:
Copied!
raster = "https://github.com/opengeos/datasets/releases/download/raster/LC09_039035_20240708_30m.tif"
raster = "https://github.com/opengeos/datasets/releases/download/raster/landsat7.tif"
m_withR = pl.LeafletMap()
m_withR.add_raster(raster)
m_withR
raster = "https://github.com/opengeos/datasets/releases/download/raster/LC09_039035_20240708_30m.tif"
raster = "https://github.com/opengeos/datasets/releases/download/raster/landsat7.tif"
m_withR = pl.LeafletMap()
m_withR.add_raster(raster)
m_withR
Out[6]:
In [7]:
Copied!
static_image = "https://th.bing.com/th/id/R.81a6e74c8adbf7f55406e8c4b80669d5?rik=HqvY9afbb1CD8g&pid=ImgRaw&r=0"
gif = "https://i.gifer.com/4j.gif"
m_withR = pl.LeafletMap()
m_withR.add_staticImage(gif, bounds=[[37, -123], [38, -121]], name="gif")
m_withR
static_image = "https://th.bing.com/th/id/R.81a6e74c8adbf7f55406e8c4b80669d5?rik=HqvY9afbb1CD8g&pid=ImgRaw&r=0"
gif = "https://i.gifer.com/4j.gif"
m_withR = pl.LeafletMap()
m_withR.add_staticImage(gif, bounds=[[37, -123], [38, -121]], name="gif")
m_withR
Out[7]:
In [8]:
Copied!
map = pl.LeafletMap()
map.add_video(
"https://static-assets.mapbox.com/mapbox-gl-js/drone.mp4",
bounds=[[37.56238816, -122.515963], [37.563391708, -122.5130939]],
)
map.center = [37.56238816, -122.5130939]
map.zoom = 14
map
map = pl.LeafletMap()
map.add_video(
"https://static-assets.mapbox.com/mapbox-gl-js/drone.mp4",
bounds=[[37.56238816, -122.515963], [37.563391708, -122.5130939]],
)
map.center = [37.56238816, -122.5130939]
map.zoom = 14
map
Out[8]:
In [9]:
Copied!
map = pl.LeafletMap()
map.add_webservice(
url="https://imagery.nationalmap.gov/arcgis/services/USGSNAIPPlus/ImageServer/WMSServer?",
lyr_name="USGSNAIPPlus:NaturalColor",
format="image/png",
transparent=True,
)
map.add_layer_control()
map
map = pl.LeafletMap()
map.add_webservice(
url="https://imagery.nationalmap.gov/arcgis/services/USGSNAIPPlus/ImageServer/WMSServer?",
lyr_name="USGSNAIPPlus:NaturalColor",
format="image/png",
transparent=True,
)
map.add_layer_control()
map
Out[9]:
In [10]:
Copied!
map = pl.LeafletMap()
map.add_split_map(
left="Esri.WorldImagery",
right="https://github.com/opengeos/datasets/releases/download/raster/landsat7.tif",
)
map.add_layer_control()
map
map = pl.LeafletMap()
map.add_split_map(
left="Esri.WorldImagery",
right="https://github.com/opengeos/datasets/releases/download/raster/landsat7.tif",
)
map.add_layer_control()
map
Out[10]:
In [11]:
Copied!
map = pl.LeafletMap()
map.add_split_map()
map.add_layer_control()
map
map = pl.LeafletMap()
map.add_split_map()
map.add_layer_control()
map
Out[11]:
Testing pypackage_example.folium (built on folium)¶
add vector and layer control panel¶
In [12]:
Copied!
m2 = flp.FoliumMap()
m2.add_vector(url)
m2.add_layer_control()
m2
m2 = flp.FoliumMap()
m2.add_vector(url)
m2.add_layer_control()
m2
Out[12]:
Make this Notebook Trusted to load map: File -> Trust Notebook
adding a split map¶
In [13]:
Copied!
m3 = flp.FoliumMap()
m3.add_vector(url)
m3.add_split_map(left_layer="OpenStreetMap", right_layer="ESRI.WorldImagery")
m3
m3 = flp.FoliumMap()
m3.add_vector(url)
m3.add_split_map(left_layer="OpenStreetMap", right_layer="ESRI.WorldImagery")
m3
Out[13]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
Copied!