<html><head></head><body><div>
<meta charset="utf-8">
<div id="compose-body-wrapper" dir="auto"><div dir="auto"><div
dir="auto">Hello,</div><div dir="auto">I'm generating a raster file with
GDAL. The pseudo-code (where the raster is loaded as 'var') for the colored
version reads:</div><div dir="auto"># Initial manipulations</div><div
dir="auto"> dims =
var.dimensions</div><div dir="auto">
shape = var.shape</div><div dir="auto">
driver_name = 'GTIFF'</div><div dir="auto">
driver =
gdal.GetDriverByName(driver_name) </div><div dir="auto">
np_dtype = var.dtype</div><div
dir="auto"> type_code =
gdal_array.NumericTypeCodeToGDALTypeCode(np_dtype)</div><div
dir="auto"> gdal_ds =
driver.Create(_my_path_, cols, rows, 1, gdal.GDT_UInt16) </div><div
dir="auto">
gdal_ds.SetProjection(_my_projection_)</div><div dir="auto">
gdal_ds.SetGeoTransform(_my_transformation_)</div><div dir="auto">#
Creation of the bands and scaled matrix </div><div dir="auto">
band =
gdal_ds.GetRasterBand(1) </div><div dir="auto">
data = var[_chosen_index_]</div><div dir="auto">
data = ma.getdata(data)</div><div
dir="auto"> data_scaled =
np.interp(data, (data.min(), data.max()), (0, 255))</div><div
dir="auto"> data_scaled2 =
data_scaled.astype(int) # This is to rescale into integers so that it can
color the layer</div><div dir="auto"># *** Lines to set up the color
palette ***</div><div dir="auto"># Write the array to band once everything
has been rescaled</div><div dir="auto">
band.WriteArray(data_scaled2)</div><div dir="auto">
gdal_ds.FlushCache() </div><div
dir="auto">This works well but the problem is that the generated file
becomes too large and difficult to work with. If I change to a black and
white representation by simply changing the 7th line to: </div><div
dir="auto"> gdal_ds =
driver.Create(out_path, cols, rows, 1, type_code) </div><div
dir="auto">The new file has a size smaller than 1% of the colored one. I
was wondering if there is anything intermediate (with colors but generating
a smaller size) or if I would need a more radical approach such as using a
driver different from GTIFF or something else.</div><div
dir="auto">Thanks.</div></div></div>
</div></body></html>