Hot to write an In-Memory GDAL Dataset to disk with python

1.2k views Asked by At

I'm trying to write an IN-Memory Dataset to a GeoTiff in Disk with gdal for python

gd_driver = gdal.GetDriverByName("MEM")
gd_raster = gd_driver.Create('pippo', src_height, src_width, src_NBands, gdal.GDT_Int16)
gd_raster.SetGeoTransform(gd_transform)
gd_raster.SetProjection(src_crs.wkt)

for i in range (0, src_NBands):
  gd_raster.GetRasterBand(i+1).WriteArray(src_data[i])

# TO tiff
drv_out = gdal.GetDriverByName('GTiff')
dset_in = gdal.Open('/vsimem/pippo', gdal.GA_ReadOnly)

drv_out.CreateCopy(file_name_out, dset_in)

but i can not open and read source dataset

1

There are 1 answers

0
maike On

I found the error.

I have to put the source dataset (In Memoery dataset) in the second argument of createcopy without open it before

...
# TO tiff
dset_tiff_out = gdal.GetDriverByName('GTiff')
# dset_tiff_in = gdal.Open('/vsimem/pippo', gdal.GA_ReadOnly)

dset_tiff_out.CreateCopy(file_name_out, gd_raster, 1)
...

many thanks