65 sagemaker
Install packages¶
Uncomment the following code blocks to install GDAL, leafmap, and localtileserver on SageMaker Studio Lab.
In [1]:
Copied!
# %pip install --find-links=https://girder.github.io/large_image_wheels --no-cache GDAL
# %pip install --find-links=https://girder.github.io/large_image_wheels --no-cache GDAL
In [2]:
Copied!
# pip install leafmap localtileserver matplotlib==3.6.3 folium==0.13.0
# pip install leafmap localtileserver matplotlib==3.6.3 folium==0.13.0
Restart the kernel after installing the packages.
In [3]:
Copied!
import leafmap.foliumap as leafmap
import leafmap.foliumap as leafmap
Visualize local raster data¶
Download a sample raster dataset.
In [4]:
Copied!
url = "https://open.gishub.org/data/raster/srtm90.tif"
leafmap.download_file(url, "dem.tif")
url = "https://open.gishub.org/data/raster/srtm90.tif"
leafmap.download_file(url, "dem.tif")
dem.tif already exists. Skip downloading. Set overwrite=True to overwrite.
Out[4]:
'/home/runner/work/leafmap/leafmap/docs/notebooks/dem.tif'
Create an interactive map.
In [5]:
Copied!
m = leafmap.Map()
m.add_raster("dem.tif", palette="terrain", layer_name="Local Raster")
m
m = leafmap.Map()
m.add_raster("dem.tif", palette="terrain", layer_name="Local Raster")
m
Out[5]:
Create a split-view map.
In [6]:
Copied!
m = leafmap.Map()
m.split_map(
left_layer="dem.tif", right_layer="dem.tif", right_args={"palette": "terrain"}
)
m
m = leafmap.Map()
m.split_map(
left_layer="dem.tif", right_layer="dem.tif", right_args={"palette": "terrain"}
)
m
Out[6]:
Visualize Cloud Optimized GeoTIFF (COG)¶
In [7]:
Copied!
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
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
Out[7]:
In [8]:
Copied!
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
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
Out[8]:
Visualize SpatioTemporal Asset Catalog (STAC) Items¶
In [9]:
Copied!
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
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
Out[9]: