Skip to content

65 sagemaker

image image image

Install packages

Uncomment the following code blocks to install GDAL, leafmap, and localtileserver on SageMaker Studio Lab.

1
# %pip install --find-links=https://girder.github.io/large_image_wheels --no-cache GDAL
1
# pip install leafmap localtileserver matplotlib==3.6.3 folium==0.13.0

Restart the kernel after installing the packages.

Import libraries

ipyleaflet currently does not work on SageMAker Studio Lab. See this issue. We can use the folium plotting backend instead.

1
import leafmap.foliumap as leafmap

Visualize local raster data

Download a sample raster dataset.

1
2
url = "https://opengeos.org/data/raster/srtm90.tif"
leafmap.download_file(url, "dem.tif")

Create an interactive map.

1
2
3
m = leafmap.Map()
m.add_raster("dem.tif", palette="terrain", layer_name="Local Raster")
m

Create a split-view map.

1
2
3
4
5
m = leafmap.Map()
m.split_map(
    left_layer="dem.tif", right_layer="dem.tif", right_args={"palette": "terrain"}
)
m

Visualize Cloud Optimized GeoTIFF (COG)

1
2
3
4
m = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"
m.add_cog_layer(url, name="COG")
m
1
2
3
4
5
m = leafmap.Map()
url = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif"
url2 = "https://github.com/opengeos/data/releases/download/raster/Libya-2023-09-13.tif"
m.split_map(left_layer=url, right_layer=url2)
m

Visualize SpatioTemporal Asset Catalog (STAC) Items

1
2
3
4
5
m = 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"
m.add_stac_layer(url, bands=["pan"], name="Panchromatic")
m.add_stac_layer(url, bands=["B3", "B2", "B1"], name="False color")
m