100 numpy to cog
In [ ]:
Copied!
# !pip install geemap rio-cogeo
# !pip install geemap rio-cogeo
In [ ]:
Copied!
import geemap
import geemap
In [ ]:
Copied!
url = "https://github.com/giswqs/leafmap/raw/master/examples/data/cog.tif"
in_cog = "cog.tif"
out_cog = "ndvi.tif"
url = "https://github.com/giswqs/leafmap/raw/master/examples/data/cog.tif"
in_cog = "cog.tif"
out_cog = "ndvi.tif"
Download a sample dataset.
In [ ]:
Copied!
geemap.download_from_url(url, in_cog)
geemap.download_from_url(url, in_cog)
Convert image to numpy array.
In [ ]:
Copied!
arr = geemap.image_to_numpy(in_cog)
arr = geemap.image_to_numpy(in_cog)
In [ ]:
Copied!
arr.shape
arr.shape
Computer NDVI.
In [ ]:
Copied!
ndvi = (arr[3] - arr[0]) / (arr[3] + arr[0])
ndvi = (arr[3] - arr[0]) / (arr[3] + arr[0])
In [ ]:
Copied!
ndvi.shape
ndvi.shape
Convert numpy array to COG.
In [ ]:
Copied!
geemap.numpy_to_cog(ndvi, out_cog, profile=in_cog)
geemap.numpy_to_cog(ndvi, out_cog, profile=in_cog)
In [ ]:
Copied!
m = geemap.Map()
m.add_raster(in_cog, indexes=[4, 1, 2], layer_name="Color infrared")
m.add_raster(out_cog, colormap="Greens", layer_name="NDVI")
m
m = geemap.Map()
m.add_raster(in_cog, indexes=[4, 1, 2], layer_name="Color infrared")
m.add_raster(out_cog, colormap="Greens", layer_name="NDVI")
m