diff --git a/CHANGES.md b/CHANGES.md index 698cfb4..e36cba5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - FIX: Add more tolerances in `geometry.simplify_footprint` to allow further simplification, and a warning in case of failure - FIX: Force 2D geometries in `rasters.crop` as `odc.geo.xr.crop` don't work with 3D geometries +- FIX: Fix nodata casting in `rasters_rio.rasterize` for float values casted into integers - OPTIM: Only write rasters on disk with `windowed=True` in case of big rasters _(w/*h > 20,000*20,000 pixels)_ - DEPR: Remove mention to DS2 in Unistra (keep only the mounting points for legacy purposes) - CI: Refactor `.gitlab-ci.yml` file with new GitLab templates diff --git a/sertit/rasters_rio.py b/sertit/rasters_rio.py index 0b19c98..ec33dc2 100644 --- a/sertit/rasters_rio.py +++ b/sertit/rasters_rio.py @@ -545,7 +545,11 @@ def rasterize( else: nodata = default_nodata - if not np.can_cast(np.array(nodata, dtype=ds.dtypes[0]), dtype): + # Check if the nodata value can be casted into the new dtype + # Floating point values that can be converted to integers are allowed + if not np.can_cast(np.array(nodata, dtype=ds.dtypes[0]), dtype) and not ( + "int" in str(dtype) and abs(nodata - int(nodata)) == 0 + ): old_nodata = nodata nodata = get_nodata_value_from_dtype(dtype) @@ -555,6 +559,9 @@ def rasterize( f"Impossible to cast nodata value ({old_nodata}) into the wanted dtype ({str(dtype)}). " f"Default nodata value for this current dtype will be used ({nodata})." ) + LOGGER.debug( + f"input nodata: {old_nodata} - nodata coming from dtype: {nodata}." + ) # Rasterize vector mask = features.rasterize(