jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
182 stars 10 forks source link

writing with Bigtiff #308

Closed mmann1123 closed 3 months ago

mmann1123 commented 3 months ago

Note to self. Bigtif can be triggered using config update

with gw.open(bgrn, stack_dim="band") as src:
                src.gw.save(
                    filename=f"../stacks/S2_SR_{quarter}_{grid}.tif",
                    nodata=nan,
                    overwrite=True,
                    num_workers=12,
                    compress="lzw",
                )
RasterioIOError: ../stacks/S2_SR_2020_Q01_linear_south-0000000000-0000000000.tif.tif: The TIFF file will be larger than 4GB, so BigTIFF is necessary.  Creation failed.

So write with:

        with gw.config.update(bigtiff="yes"):
            with gw.open(bgrn, stack_dim="band") as src:
                src = src.astype("float32")
                src.gw.save(
                    filename=f"../stacks/S2_SR_{quarter}_{grid}.tif",
                    nodata=nan,
                    overwrite=True,
                    num_workers=12,
                    compress="lzw",
                )
mmann1123 commented 3 months ago

Self q&a here closing

mmann1123 commented 3 months ago

Need to set bounds and bigtif. Maybe bigtif or gdal cache are limited with save?

Suggested solution

from geowombat.backends.rasterio_ import get_file_bounds
bounds = get_file_bounds( [files],  return_bounds=True,   )

        with gw.config.update(bigtiff="yes", ref_bounds = bounds):
            with gw.open(bgrn, stack_dim="band") as src:
                src = src.astype("float32")
                src.gw.save(
                    filename=f"../stacks/S2_SR_{quarter}_{grid}.tif",
                    nodata=nan,
                    overwrite=True,
                    num_workers=12,
                    compress="lzw",
                )