Skip to content

42 create cog

image image image

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap
1
import leafmap

Provide a dataset path or URL.

1
url = "https://opengeos.org/data/raster/srtm90.tif"

Validate COG.

1
leafmap.cog_validate(url)
1
leafmap.cog_validate(url, verbose=True)

Convert the image to tiled COG.

1
2
out_cog = "cog.tif"
leafmap.image_to_cog(url, out_cog)

Validate COG.

1
leafmap.cog_validate(out_cog)
1
leafmap.cog_validate(out_cog, verbose=True)

Add COG to map.

1
2
3
4
m = leafmap.Map()
m.add_raster(out_cog, palette="terrain", layer_name="Local COG")
m.add_cog_layer(url, palette="gist_earth", name="Remote COG")
m