rioxarray
rioxarray copied to clipboard
Does rioxarray support generating overviews and exporting them?
I see reading, but I couldn't find any export. https://corteva.github.io/rioxarray/html/examples/COG.html
With GDAL 3.1+: https://gdal.org/drivers/raster/cog.html#raster-cog
xds.rio.to_raster("raster.tif", driver="COG")
See also: https://corteva.github.io/rioxarray/stable/examples/convert_to_raster.html
Thanks! Is there an equivalent of:
dst.build_overviews(factors, Resampling.average)
from https://rasterio.readthedocs.io/en/latest/topics/overviews.html
but using xarray + dask?
Oh! It's built into COG! I just tried:
import rioxarray as rio
path = "something.tif"
ds = rio.open_rasterio(path, overview_level=0)
ds.rio.to_raster("raster.tif", driver="COG")
From
OVERVIEWS=[AUTO/IGNORE_EXISTING/FORCE_USE_EXISTING/NONE]: Describe the behavior regarding overview generation and use of source overviews.
AUTO (default): source overviews will be used if present (even if the dimension of the smallest level is not < 512 pixels), and, if not present, overviews will be automatically generated in the output file.
IGNORE_EXISTING: potential existing overviews on the source dataset will be ignored and new overviews will be automatically generated.
FORCE_USE_EXISTING: potential existing overviews on the source will be used (even if the dimension of the smallest level is not < 512 pixels). If there is no source overview, this is equivalent to specifying NONE.
NONE: potential source overviews will be ignored, and no overview will be generated.
But is there a way to specify with overview levels?
Did you try ALIGNED_LEVELS?
How do I specify ALIGNED_LEVELS
import rioxarray
fp = 'something.tif'
ds = rioxarray.open_rasterio(fp, overview_level=1)
ds.rio.to_raster("test.tif", driver="COG", ALIGNED_LEVELS=1)
Looks like it is a number between 1-10 and requires setting TILING_SCHEME as well.
ds.rio.to_raster("test.tif", driver="COG", ALIGNED_LEVELS=1, TILING_SCHEME="GoogleMapsCompatible") seems to output a bunch of levels
for level in range(0, 7):
print(rioxarray.open_rasterio("test.tif", overview_level=level))
Up to 7
The "COG" driver seems to be a Copy-only driver (in GDAL terminology), without a Create method, so will rioxarray be able to use it without having to make a complete in-memory copy of the dataset?
I think this is what you are referring to: ref
The best way to find out is to give it a try and see what happens.