95 create cog
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import geemap
import geemap
If you are using a recently implemented geemap feature that has not yet been released to PyPI or conda-forge, you can uncomment the following line to install the development version from GitHub.
In [3]:
Copied!
# geemap.update_package()
# geemap.update_package()
Provide a dataset path or URL.
In [4]:
Copied!
url = "https://github.com/giswqs/data/raw/main/raster/srtm90.tif"
url = "https://github.com/giswqs/data/raw/main/raster/srtm90.tif"
Validate COG.
In [5]:
Copied!
geemap.cog_validate(url)
geemap.cog_validate(url)
The following warnings were found:
- The file is greater than 512xH or 512xW, it is recommended to include internal overviews
Out[5]:
(True, [], ['The file is greater than 512xH or 512xW, it is recommended to include internal overviews'])
In [6]:
Copied!
geemap.cog_validate(url, verbose=True)
geemap.cog_validate(url, verbose=True)
Out[6]:
Info(Path='https://github.com/giswqs/data/raw/main/raster/srtm90.tif', Driver='GTiff', COG=True, Compression='LZW', ColorSpace=None, COG_errors=None, COG_warnings=['The file is greater than 512xH or 512xW, it is recommended to include internal overviews'], Profile=Profile(Bands=1, Width=4269, Height=2465, Tiled=True, Dtype='int16', Interleave='BAND', AlphaBand=False, InternalMask=False, Nodata=None, ColorInterp=('gray',), ColorMap=False, Scales=(1.0,), Offsets=(0.0,)), GEO=Geo(CRS='EPSG:4326', BoundingBox=(-120.75592734926073, 36.63401097629554, -117.30451019614512, 38.6269234341147), Origin=(-120.75592734926073, 38.6269234341147), Resolution=(0.0008084837557075694, -0.0008084837557075694), MinZoom=7, MaxZoom=11), Tags={'Image Metadata': {'AREA_OR_POINT': 'Area'}, 'Image Structure': {'COMPRESSION': 'LZW', 'INTERLEAVE': 'BAND'}}, Band_Metadata={'Band 1': BandMetadata(Description='elevation', ColorInterp='gray', Offset=0.0, Scale=1.0, Metadata={})}, IFD=[IFD(Level=0, Width=4269, Height=2465, Blocksize=(256, 256), Decimation=0)])
Convert the image to tiled COG.
In [7]:
Copied!
out_cog = "cog.tif"
geemap.image_to_cog(url, out_cog)
out_cog = "cog.tif"
geemap.image_to_cog(url, out_cog)
Reading input: https://github.com/giswqs/data/raw/main/raster/srtm90.tif Adding overviews... Updating dataset tags... Writing output to: /home/runner/work/geospatial-notebooks/geospatial-notebooks/docs/geemap/cog.tif
Validate COG.
In [8]:
Copied!
geemap.cog_validate(out_cog)
geemap.cog_validate(out_cog)
Out[8]:
(True, [], [])
In [9]:
Copied!
geemap.cog_validate(out_cog, verbose=True)
geemap.cog_validate(out_cog, verbose=True)
Out[9]:
Info(Path='/home/runner/work/geospatial-notebooks/geospatial-notebooks/docs/geemap/cog.tif', Driver='GTiff', COG=True, Compression='DEFLATE', ColorSpace=None, COG_errors=None, COG_warnings=None, Profile=Profile(Bands=1, Width=4269, Height=2465, Tiled=True, Dtype='int16', Interleave='BAND', AlphaBand=False, InternalMask=False, Nodata=None, ColorInterp=('gray',), ColorMap=False, Scales=(1.0,), Offsets=(0.0,)), GEO=Geo(CRS='EPSG:4326', BoundingBox=(-120.75592734926073, 36.63401097629554, -117.30451019614512, 38.6269234341147), Origin=(-120.75592734926073, 38.6269234341147), Resolution=(0.0008084837557075694, -0.0008084837557075694), MinZoom=7, MaxZoom=11), Tags={'Image Metadata': {'AREA_OR_POINT': 'Area', 'OVR_RESAMPLING_ALG': 'NEAREST'}, 'Image Structure': {'COMPRESSION': 'DEFLATE', 'INTERLEAVE': 'BAND', 'LAYOUT': 'COG'}}, Band_Metadata={'Band 1': BandMetadata(Description='elevation', ColorInterp='gray', Offset=0.0, Scale=1.0, Metadata={})}, IFD=[IFD(Level=0, Width=4269, Height=2465, Blocksize=(512, 512), Decimation=0), IFD(Level=1, Width=2135, Height=1233, Blocksize=(512, 512), Decimation=2), IFD(Level=2, Width=1068, Height=617, Blocksize=(512, 512), Decimation=4), IFD(Level=3, Width=534, Height=309, Blocksize=(512, 512), Decimation=8)])
Add COG to map.
In [10]:
Copied!
m = geemap.Map()
m.add_local_tile(out_cog, palette="dem", layer_name="Local COG")
m.add_cog_layer(url, palette="gist_earth", name="Remote COG")
m
m = geemap.Map()
m.add_local_tile(out_cog, palette="dem", layer_name="Local COG")
m.add_cog_layer(url, palette="gist_earth", name="Remote COG")
m
Out[10]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update:
2022-03-14