Re: How are calculate_default_transform and aligned_target different?

Sean Gillies

Hi Amaury,

Rasterio's calculate_default_transform is only a thin wrapper around GDALSuggestedWarpOutput2: The behavior you see in GDAL is implemented in the gdalwarp program and is only partially implemented in rasterio's rio-warp command. So, to get the same behavior, you would need to port some logic from C (the gdalwap_lib.cpp file, if I remember correctly) to Python.

We'd like to change rasterio's warp API to align better with GDAL but no work on this has started yet.

On Tue, Jul 6, 2021 at 4:20 AM <amaury.dehecq@...> wrote:

Hi all,

on the same topic, is there an easy way to get the destination parameters (transform, width, height) exactly as GDAL would do, considering the user might provide any of, or a combination of, the following: dst_bounds, dst_width/height, dst_res.

I understand that if dst_width/height or resolution are provided, the output transformation and width/height can easily be calculated using calculate_default_transform (and aligned_target if the resolution is to be strictly enforced). But what if dst_bounds are also set?

Let's consider the following cases:

- dst_bounds is set alone -> GDAL output strictly enforces the output bounds but keeps the output resolution as close as possible to the input resolution

- dst_bounds and res are set -> GDAL output enforces the output resolution and use the bounds that are as close as possible to the requested bounds

- dst_bounds and res are set+ tap option -> same as before but output bounds is a multiple of the resolution

- dst_bounds and width/height are set -> GDAL outputs shape and bounds are strictly enforced, the resolution is set accordingly.

Currently, I cannot find an easy way to do this with rasterio. At least a specific, non trivial order of rasterio functions have to be called, to get exactly this behavior. There could possibly be a specific rasterio function to do this.

Thanks in advance!




Sean Gillies

Join to automatically receive all group messages.