[gdal-dev] Some python learner questions

Laurențiu Nicola lnicola at dend.ro
Sat Sep 20 00:36:51 PDT 2025


Hi Stefan,

Without testing, I assume these will work:

gdal.Translate("out.tif", ds, options=["-scale", "1", "100"])
gdal.Translate("out.tif", ds, options=gdal.TranslateOptions(scaleParams=[[1, 100]]))

For gdal_calc, there are two ways, you either load them as numpy arrays and do your thing, or you use the new algorithm API in GDAL 3.11. The first method is easier, but you should keep in mind the memory usage.

Laurentiu



On Sat, Sep 20, 2025, at 10:15, Stefan Gofferje via gdal-dev wrote:
> Morning!
>
> I'm currently trying to learn Python and in my quest to do so, I'm 
> trying to rewrite some of bash scripts which use the GDAL tools into 
> Python, namely the ones that I use to process Sentinel 2 imagery.
>
> I'm a little bit at a loss on how I would translate gdal_translate's 
> scale function into Python, e.g.
>
> gdal_translate -ot Byte -scale ${min} ${max} 0 255 a.tiff a_scaled.tiff
>
> Then, I assume, to replicate the function of gdalcalc, I would have to 
> load the bands into numpy arrays, do the calculations with the arrays 
> and write those arrays back as bands in a tiff? Or is there a smarter 
> way to do that?
>
> BR: Stefan
>
> -- 
>   (o_   Stefan Gofferje            | SCLT, MCP, CCSA
>   //\   Reg'd Linux User #247167   | VCP #2263
>   V_/_  https://www.gofferje.net   | https://www.saakeskus.fi
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list