03 cog stac
Using Cloud Optimized GeoTIFF (COG) and SpatioTemporal Asset Catalog (STAC)
Uncomment the following line to install leafmap if needed.
# !pip install leafmap
Working with Cloud Optimized GeoTIFF (COG)
A Cloud Optimized GeoTIFF (COG) is a regular GeoTIFF file, aimed at being hosted on a HTTP file server, with an internal organization that enables more efficient workflows on the cloud. It does this by leveraging the ability of clients issuing HTTP GET range requests to ask for just the parts of a file they need.
More information about COG can be found at https://www.cogeo.org/in-depth.html
Some publicly available Cloud Optimized GeoTIFFs:
- https://stacindex.org/
- https://cloud.google.com/storage/docs/public-datasets/landsat
- https://www.digitalglobe.com/ecosystem/open-data
- https://earthexplorer.usgs.gov/
For this demo, we will use data from https://www.maxar.com/open-data/california-colorado-fires for mapping California and Colorado fires. A List of COGs can be found here.
import os
import leafmap
# Use the TiTiler demo endpoint. Replace this if needed.
os.environ["TITILER_ENDPOINT"] = "https://titiler.xyz"
Create an interactive map.
Map = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"
Retrieve the bounding box coordinates of the COG file.
leafmap.cog_bounds(url)
[22.599490732206565, 32.75052266794987, 22.65706605051743, 32.79916288270382]
Retrieve the centroid coordinates of the COG file.
leafmap.cog_center(url)
(22.628278391361995, 32.774842775326846)
Retrieve the band names of the COG file.
leafmap.cog_bands(url)
['b1', 'b2', 'b3']
Retrieves the tile layer URL of the COG file.
leafmap.cog_tile(url)
'https://titiler.xyz/cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=https%3A%2F%2Fgithub.com%2Fopengeos%2Fdata%2Freleases%2Fdownload%2Fraster%2FLibya-2023-07-01.tif&bidx=1&bidx=2&bidx=3&rescale=41.0%2C235.0&rescale=45.0%2C216.0&rescale=40.0%2C197.0'
Add a COG layer to the map.
Map.add_cog_layer(url, name="Fire (pre-event)")
url2 = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif"
Map.add_cog_layer(url2, name="Fire (post-event)")
Map
Use custom colormap.
url = "https://clarkcga-aquaculture.s3.amazonaws.com/data/el_salvador/cover/El_Salvador_Landcover_2022.tif"
custom_cmap = {
"0": "#000000",
"1": "#008040",
"2": "#ff0000",
"3": "#ffff00",
"4": "#8000ff",
"5": "#8080ff",
"6": "#00ff00",
"7": "#c0c0c0",
"8": "#16002d",
"9": "#ff80ff",
"10": "#b3ffb3",
"11": "#ff8080",
"12": "#ffffbf",
"13": "#000080",
"14": "#808000",
"15": "#00ffff",
}
m = leafmap.Map()
m.add_cog_layer(url, colormap=custom_cmap, name="El_Salvador")
m
Working with SpatioTemporal Asset Catalog (STAC)
The SpatioTemporal Asset Catalog (STAC) specification provides a common language to describe a range of geospatial information, so it can more easily be indexed and discovered. A 'spatiotemporal asset' is any file that represents information about the earth captured in a certain space and time. The initial focus is primarily remotely-sensed imagery (from satellites, but also planes, drones, balloons, etc), but the core is designed to be extensible to SAR, full motion video, point clouds, hyperspectral, LiDAR and derived data like NDVI, Digital Elevation Models, mosaics, etc. More information about STAC can be found at https://stacspec.org/
Some publicly available SpatioTemporal Asset Catalog (STAC):
For this demo, we will use STAC assets from https://stacindex.org/catalogs/spot-orthoimages-canada-2005#/?t=catalogs
Create an interactive map.
Map = 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"
Retrieve the bounding box coordinates of the STAC file.
leafmap.stac_bounds(url)
[-111.6453245, 60.59892389999882, -110.1583693, 61.30928879999903]
Retrieve the centroid coordinates of the STAC file.
leafmap.stac_center(url)
(-110.90184690000001, 60.95410634999892)
Retrieve the band names of the STAC file.
leafmap.stac_bands(url)
['pan', 'B1', 'B2', 'B3', 'B4']
Retrieve the tile layer URL of the STAC file.
leafmap.stac_tile(url, bands=["B3", "B2", "B1"])
'https://titiler.xyz/stac/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=https%3A%2F%2Fcanada-spot-ortho.s3.amazonaws.com%2Fcanada_spot_orthoimages%2Fcanada_spot5_orthoimages%2FS5_2007%2FS5_11055_6057_20070622%2FS5_11055_6057_20070622.json&assets=B3&assets=B2&assets=B1&rescale=23.0%2C168.0'
Add a STAC layer to the map.
Map.add_stac_layer(url, bands=["pan"], name="Panchromatic")
Map.add_stac_layer(url, bands=["B3", "B2", "B1"], name="False color")
Map