<div dir="auto"></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr"> <<a href="mailto:gdal-dev-request@lists.osgeo.org">gdal-dev-request@lists.osgeo.org</a>> schrieb am Fr., 14. Nov. 2025, 03:43:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send gdal-dev mailing list submissions to<br>
        <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:gdal-dev-request@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev-request@lists.osgeo.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:gdal-dev-owner@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev-owner@lists.osgeo.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of gdal-dev digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: GDAL CLI converting to output datatype before performing<br>
      calculation (Daniel Baston)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 13 Nov 2025 21:42:55 -0500<br>
From: Daniel Baston <<a href="mailto:dbaston@gmail.com" target="_blank" rel="noreferrer">dbaston@gmail.com</a>><br>
To: Henry Walshaw <<a href="mailto:henry@floodmapp.com" target="_blank" rel="noreferrer">henry@floodmapp.com</a>><br>
Cc: "<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a>" <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a>><br>
Subject: Re: [gdal-dev] GDAL CLI converting to output datatype before<br>
        performing calculation<br>
Message-ID:<br>
        <CA+K_q_p3KD9JTs+qznP1r6utx81bSuL1SSghTAR0yf0BJN=<a href="mailto:47w@mail.gmail.com" target="_blank" rel="noreferrer">47w@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Henry,<br>
<br>
Thanks for the example. This looks like a bug in GDAL 3.12, affecting<br>
calculations where the input has a NoData value. The simplest workaround I<br>
see for now is to rewrite the command as a pipeline:<br>
<br>
gdal raster pipeline calc -i "A=sample.tif" --calc "A > 0 ? 1 : 0" --nodata<br>
none ! materialize ! set-type --ot Byte ! write footprint_b.tif --overwrite<br>
<br>
Dan<br>
<br>
On Thu, Nov 13, 2025 at 8:32?PM Henry Walshaw <<a href="mailto:henry@floodmapp.com" target="_blank" rel="noreferrer">henry@floodmapp.com</a>> wrote:<br>
<br>
> Thanks for the example Daniel. I can confirm if I try the same task as you<br>
> with the 1 pixel raster I do get the result as expected. Unfortunately for<br>
> the actual data it doesn?t hold true. Using a sample.tif available here:<br>
> <a href="https://www.dropbox.com/scl/fi/fdj4acszchg0ao132kf6g/sample.tif?rlkey=ro5mgecpdp4oqcv0kljfh0go3&st=er04s2mm&dl=0" rel="noreferrer noreferrer" target="_blank">https://www.dropbox.com/scl/fi/fdj4acszchg0ao132kf6g/sample.tif?rlkey=ro5mgecpdp4oqcv0kljfh0go3&st=er04s2mm&dl=0</a><br>
><br>
> I can try the following (The Q text as data tool is what I?m using to do<br>
> the quick calc at the end: <a href="https://harelba.github.io/q/" rel="noreferrer noreferrer" target="_blank">https://harelba.github.io/q/</a> )<br>
><br>
><br>
> $ gdal raster convert sample.tif --output-format XYZ cells.txt<br>
><br>
> $ q "select count(*) from cells.txt where c3 > 0"<br>
><br>
> 22829<br>
><br>
> $ q "select count(*) from cells.txt where c3 >= 0.5"<br>
><br>
> 11518<br>
><br>
> $ gdal raster calc -i "A=sample.tif" -o footprint_b.tif --calc "A > 0 ? 1 : 0" --nodata none --ot Byte<br>
><br>
> $ gdal raster convert footprint.tif --output-format XYZ footprint_cells.txt<br>
><br>
> $ q "select count(*) from footprint_cells.txt where c3 = 1"<br>
><br>
> 11518<br>
><br>
> So you can see that the rounding in this case is happening before the<br>
> calculation. For what it?s worth I?m running GDAL off the latest alpine<br>
> container <a href="http://ghcr.io/osgeo/gdal:alpine-normal-latest" rel="noreferrer noreferrer" target="_blank">ghcr.io/osgeo/gdal:alpine-normal-latest</a>, so<br>
><br>
><br>
> $ gdal --version<br>
><br>
> GDAL 3.13.0dev-fbde9c11c976a693992f7688ecf324dd11e190f1, released 2025/11/12<br>
><br>
> Hopefully it?s just a bug on my end!<br>
><br>
> On 14/11/25 01:40, Daniel Baston wrote:<br>
><br>
> Hi Henry,<br>
><br>
> The input values should not be rounded before doing the calculation. I get<br>
> a correct result with both 3.12 and 3.11.5:<br>
><br>
> $ gdal raster create --size 1,1 --burn 0.1 --output-data-type Float64<br>
> depth.tif<br>
> $ gdal raster calc -i "A=depth.tif" -o footprint_b.tif --calc "A > 0 ? 1 :<br>
> 0" --nodata none --ot Byte<br>
> $ gdal raster convert footprint_b.tif --output-format XYZ /vsistdout/<br>
> ERROR 6: Read or update mode not supported on /vsistdout<br>
> 0.5 0.5 1<br>
><br>
> Dan<br>
><br>
> On Thu, Nov 13, 2025 at 12:49?AM Henry Walshaw via gdal-dev <<br>
> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a>> wrote:<br>
><br>
>> Hi all,<br>
>><br>
>> In the docs for gdal raster calc (<br>
>> <a href="https://gdal.org/en/stable/programs/gdal_raster_calc.html#cmdoption-calc" rel="noreferrer noreferrer" target="_blank">https://gdal.org/en/stable/programs/gdal_raster_calc.html#cmdoption-calc</a><br>
>> <https://_>) it states<br>
>><br>
>> Input rasters will be converted to 64-bit floating point numbers before<br>
>> performing calculations.<br>
>><br>
>> However I?ve found that when using an integer output datatype the base<br>
>> data is rounded to an integer before performing the calculation. e.g.<br>
>> converting a flood depth input.tif raster to a simple water / no water<br>
>> footprint:<br>
>><br>
>><br>
>> gdal raster calc -i "A=depth.tif" -o footprint_b.tif --calc "A > 0 ? 1 : 0" --nodata none --ot Byte<br>
>><br>
>> The expected result for a value of (say) 0.1 is 1, but in the above<br>
>> calculation it comes out as 0. Obviously I can leave the output datatype<br>
>> alone so it stays the same as the input?s 64-bit float, but it seems<br>
>> unnecessary. Am I looking at a bug, or is this expected behaviour?<br>
>><br>
>> Regards,<br>
>><br>
>> Henry<br>
>> &#8203;<br>
>> _______________________________________________<br>
>> gdal-dev mailing list<br>
>> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a><br>
>> <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
>><br>
> &#8203;<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251113/68dd5567/attachment.htm" rel="noreferrer noreferrer" target="_blank">http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251113/68dd5567/attachment.htm</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
<br>
<br>
------------------------------<br>
<br>
End of gdal-dev Digest, Vol 258, Issue 14<br>
*****************************************<br>
</blockquote></div>