<div dir="ltr">Hi all,<br><br>I'm seeing a weird behaviour when converting vectors to rasters.<br><br>I have a polygons layer with a "value" field that has 2 decimal places.<br><br>Converting it to raster with gdal_rasterize, the output is different if I choose it as Float32 or Float64.<br><br>Here is a sample Project: <a href="https://cld.pt/dl/download/61894ebd-ade0-4f12-8aa3-1405ab2690cc/Float_Issue_Project.zip">https://cld.pt/dl/download/61894ebd-ade0-4f12-8aa3-1405ab2690cc/Float_Issue_Project.zip</a> <br><div><br></div><div>These are the commands I use (inside QGIS or in CLI):</div><div><br></div>gdal_rasterize -l polygons -a value -tr 5.0 5.0 -a_nodata 0.0 -te 61738.6841 107228.3171 63464.9242 108429.7802 -ot Float32 -of GTiff D:\Testes\Float_Issue\polygons.gpkg D:/Testes/Float_Issue/polygons_rasterize_float32.tif<br><div><br></div><div>Info:</div>Name    polygons_rasterize_float32<br>Path        D:\Testes\Float_Issue\polygons_rasterize_float32.tif<br>CRS       EPSG:3763 - ETRS89 / Portugal TM06 - Projected<br>Extent  61738.6840999999985797,107229.7801999999937834 : 63463.6840999999985797,108429.7801999999937834<br>Unit   meters<br>Width   345<br>Height     240<br>Data type  Float32 - Thirty two bit floating point<br>GDAL Driver Description        GTiff<br>GDAL Driver Metadata     GeoTIFF<br>Dataset Description    D:\Testes\Float_Issue\polygons_rasterize_float32.tif<br>Compression       <br>Band 1        <br>STATISTICS_MAXIMUM=18537<br>STATISTICS_MEAN=3782.009546874<br>STATISTICS_MINIMUM=0.12999999523163<br>STATISTICS_STDDEV=7001.5216220675<br>STATISTICS_VALID_PERCENT=100<br>More information      <br>AREA_OR_POINT=Area<br>Dimensions        X: 345 Y: 240 Bands: 1<br>Origin  61738.7,108430<br>Pixel Size      5,-5<br><br><br>gdal_rasterize -l polygons -a value -tr 5.0 5.0 -a_nodata 0.0 -te 61738.6841 107228.3171 63464.9242 108429.7802 -ot Float64 -of GTiff D:\Testes\Float_Issue\polygons.gpkg D:/Testes/Float_Issue/polygons_rasterize_float64.tif<br><div><br></div><div>Info:<br></div>Name   polygons_rasterize_float64<br>Path        D:\Testes\Float_Issue\polygons_rasterize_float64.tif<br>CRS       EPSG:3763 - ETRS89 / Portugal TM06 - Projected<br>Extent  61738.6840999999985797,107229.7801999999937834 : 63463.6840999999985797,108429.7801999999937834<br>Unit   meters<br>Width   345<br>Height     240<br>Data type  Float64 - Sixty four bit floating point<br>GDAL Driver Description        GTiff<br>GDAL Driver Metadata     GeoTIFF<br>Dataset Description    D:/Testes/Float_Issue/polygons_rasterize_float64.tif<br>Compression       <br>Band 1        <br>STATISTICS_MAXIMUM=18537<br>STATISTICS_MEAN=3782.0095468599<br>STATISTICS_MINIMUM=0.13<br>STATISTICS_STDDEV=7001.521622075<br>STATISTICS_VALID_PERCENT=100<br>More information  <br>AREA_OR_POINT=Area<br>Dimensions        X: 345 Y: 240 Bands: 1<br>Origin  61738.7,108430<br>Pixel Size      5,-5<br><div><br></div><div>Looking at output in Value Tool:<br></div><br><div><img src="cid:ii_kgtiezuy0" alt="image.jpeg" width="356" height="97"><br><br></div><br>So, if the conversion is to a Float64 raster, pixel values have 2 decimal places, as the original data.<br>If the conversion is to a Float32 raster, several pixel values assume 16 decimal places. <br><br>Float32: 0.2199999988079071<br>Float64: 0.22<br>Original value: 0.22<br><br><br>Where this becomes a serious problem is when the values are used, for instance, for a reclassification process (with Reclassify by Table). Imagine these rules:<br><br>[0 - 0.22[ = 1<br>[0.22 - 0.5[ = 2<br>>= 0.5 = 3<br><br>Pixels 0.22 are reclassified as 2;<br>Pixels 0.2199999988079071 are reclassified as 1.<br><br><div><img src="cid:ii_kgtij8w21" alt="image.jpeg" width="410" height="170"><br><br></div><br>So, Float64 gives the right results and Float32 gives wrong results.<br><br>But how can this be explained, if all input values can fall within both a Float32 and Float64 range of values?<br><br>  Float32       -3.4E38           3.4E38<br>  Float64       -1.79E308         1.79E308<br>  <br>  <br><div>Even more strange is, if instead of gdal_rasterize I use OTB Rasterization, no matter whether I use float (Float32) or double (Float64) dtype, I always get wrong results, just like gdal_rasterize with Float32.</div><div><br></div><div>Should we change the default gdal output to Float64? Or is this a deeper issue?</div><div><br></div><div>Thanks.</div><div><br></div><div>Best regards,</div><div>Pedro Venâncio</div><div><br></div></div>