Skip to content

Commit

Permalink
Re-ordering source/destination nodata sections
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Jan 26, 2024
1 parent 5523d8b commit 4ba3281
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions geoutils/raster/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ def reproject(
# Warning: this will not work for multiple bands with different dtypes
dtype = self.dtypes[0]

# Set source nodata if provided
# --- Set source nodata if provided -- #
if force_source_nodata is None:
src_nodata = self.nodata
else:
Expand All @@ -2097,24 +2097,14 @@ def reproject(
)
)

# Create a BoundingBox if required
if bounds is not None:
if not isinstance(bounds, rio.coords.BoundingBox):
bounds = rio.coords.BoundingBox(
bounds["left"],
bounds["bottom"],
bounds["right"],
bounds["top"],
)

# --- Set destination nodata if provided -- #
# This is needed in areas not covered by the input data.
# If None, will use GeoUtils' default, as rasterio's default is unknown, hence cannot be handled properly.
if nodata is None:
nodata = self.nodata
if nodata is None:
nodata = _default_nodata(dtype)
# if nodata is already being used, raise a warning.
# If nodata is already being used, raise a warning.
# TODO: for uint8, if all values are used, apply rio.warp to mask to identify invalid values
if not self.is_loaded:
warnings.warn(
Expand All @@ -2129,6 +2119,16 @@ def reproject(
f"self.set_nodata()."
)

# Create a BoundingBox if required
if bounds is not None:
if not isinstance(bounds, rio.coords.BoundingBox):
bounds = rio.coords.BoundingBox(
bounds["left"],
bounds["bottom"],
bounds["right"],
bounds["top"],
)

from geoutils.misc import resampling_method_from_str

# --- Basic reprojection options, needed in all cases. --- #
Expand Down

0 comments on commit 4ba3281

Please sign in to comment.