Skip to content

Add Cloud Optimized GeoTIFF

image image image

This example demonstrates how to use leafmap.foliumap.Map.add_geotiff to load a Cloud Optimized GeoTIFF (COG) directly in the browser using the georaster-layer-for-leaflet plugin.

1
# %pip install leafmap
1
import leafmap.foliumap as leafmap

Visualizing multi-band GeoTIFFs

1
2
3
4
5
6
m = leafmap.Map()
cog_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_naip.tif"
m.add_geotiff(cog_url, name="NAIP", indexes=[1, 2, 3])
m.add_layer_control()
m.add_opacity_control()
m

Visualizing single-band GeoTIFFs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
m = leafmap.Map()
cog_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_hag.tif"
m.add_geotiff(
    cog_url,
    name="HAG",
    vmin=0,
    vmax=10,
    palette="terrain",
)
m.add_layer_control()
m.add_opacity_control()
m

Visualizing multiple layers simultaneously

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
m = leafmap.Map()
naip_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_naip.tif"
hag_url = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_hag.tif"

m.add_geotiff(
    naip_url,
    name="NAIP",
)
m.add_geotiff(
    hag_url,
    name="HAG",
    vmin=0,
    vmax=10,
    palette="terrain",
)

in_geojson = "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_buildings_train.geojson"
m.add_geojson(in_geojson, layer_name="Buildings")

m.add_layer_control()
m.add_opacity_control()
m