Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created March 19, 2024 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/8f58baa4ee7f5f8d16eb87b0e5d61613 to your computer and use it in GitHub Desktop.
Save mdsumner/8f58baa4ee7f5f8d16eb87b0e5d61613 to your computer and use it in GitHub Desktop.
gdal_create -outsize 36000 17999 -ot Int8 -co SPARSE_OK=YES -a_srs EPSG:4326 -a_ullr 0 17999 0 36000 weird.tif
gdal_translate weird.tif cog.tif  -of COG
gdalinfo cog.tif | grep Overviews
#  Overviews: 18000x8999, 9000x4499, 4500x2249, 2250x1124, 1125x562, 562x281, 281x14

import xarray
from odc.geo.xr import assign_crs
from odc.geo.cog import write_cog

ds = xarray.open_dataset("weird.tif")
ds = assign_crs(ds, crs="EPSG:4326")  ## do something to tag it as odc


write_cog(ds["band_data"], "odc.tif")
os.system("gdalinfo odc.tif | grep Overviews")
#  Overviews: 18000x9000, 9000x4500, 4500x2250, 2250x1125, 1125x563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment