<html><head></head><body><div>
<meta charset="utf-8">
<div id="compose-body-wrapper" dir="auto"><div dir="auto"><div
dir="auto">Hi Scott,</div><div dir="auto">As I mentioned to Laurentiu, I'm
still not getting the handle on how to use overviews but will keep working
at it. However, this is only useful to me (and probably to other people) if
they can be used from a python script, not from the OS.</div><div
dir="auto">Thanks,</div><div
dir="auto">Arturo</div><div><br></div></div><div dir="auto"><br></div><div
dir="auto" id="tmjah_g_1299"><br></div></div><div class="replyHeader"
dir="auto">Scott wrote:</div><br><br><div><blockquote
cite="mid:600916e2-f6f6-3f2d-25af-65430f6ddcda@postholer.com" type="cite"
style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex"><div>As a test you can skip the whole python
debacle and try this:</div><div><br></div><div>gdal_translate -f COG -co
COMPRESS=DEFLATE -scale 0 255 -ot Byte source.tif
target.tif</div><div><br></div><div><br></div><div><div>On 6/1/23 07:35,
afernandez wrote:</div></div><br><blockquote class="gmail_quote"
type="cite" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex"><div> Hello,</div><div> 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> # Initial
manipulations</div><div> dims =
var.dimensions</div><div> shape = var.shape</div><div>
driver_name = 'GTIFF'</div><div> driver =
gdal.GetDriverByName(driver_name)</div><div>
np_dtype = var.dtype</div><div>
type_code = gdal_array.NumericTypeCodeToGDALTypeCode(np_dtype)</div><div>
gdal_ds =
driver.Create(_my_path_, cols, rows, 1, > gdal.GDT_UInt16)</div><div>
gdal_ds.SetProjection(_my_projection_)</div><div>
gdal_ds.SetGeoTransform(_my_transformation_)</div><div> # Creation of the
bands and scaled matrix</div><div> band
= gdal_ds.GetRasterBand(1)</div><div> data =
var[_chosen_index_]</div><div> data =
ma.getdata(data)</div><div>
data_scaled = np.interp(data, (data.min(), data.max()), (0, >
255))</div><div> data_scaled2 =
data_scaled.astype(int) # This is to rescale > into integers so that it
can color the layer</div><div> # *** Lines to set up the color palette
***</div><div> # Write the array to band once everything has been
rescaled</div><div> band.WriteArray(data_scaled2)</div><div>
gdal_ds.FlushCache()</div><div> 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>
gdal_ds = driver.Create(out_path, cols, rows, 1,
type_code)</div><div> 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> Thanks.</div><div> >
_______________________________________________</div><div> gdal-dev mailing
list</div><div> gdal-dev@lists.osgeo.org</div><br></blockquote><div>
https://lists.osgeo.org/mailman/listinfo/gdal-dev</div><div>_______________________________________________</div><div>gdal-dev
mailing
list</div><div>gdal-dev@lists.osgeo.org</div><div>https://lists.osgeo.org/mailman/listinfo/gdal-dev</div></blockquote></div>
</div></body></html>