I have a bunch of rasters I need to crop to a bounding box, perform come calculations with, and then close; I have no need to keep the cropped raster.
So far I've only been able to crop using
gdal.Warp(dest_file, src_object, bbox), which creates the unwanted dest_file.
I'd like dest_file to point to an empty gdal object, but can not figure out how to initialize one. I've created one in memory using:
mem_drv = gdal.GetDriverByName('MEM') dest = mem_drv.Create('', rast.RasterXSize, rast.RasterYSize, 1, gdal.GDT_Float32) dest.SetProjection(rast.GetProjection()) dest.SetGeoTransform(rast.GetTGeoTransform())
rast is an raster opened with
This lets me store the output of gdal.Warp in memory but it does not crop it; I'm assuming because the width is hard coded in the creation routine.
What is the best way to store the cropped image in memory?
Should I just get the pixel spacing from the original raster and initialize the size of
dest using this?