#### Question about code fragment in features.geometry_window()

Shinji Suzuki

Hi.
later get transformed.
https://github.com/mapbox/rasterio/blob/master/rasterio/features.py#L451

What I don't understand are;
that should be related to 'bottom'?
2. Same value is computed twice.(e.g. left - pad_x). Since the
computed values are used later only for obtaining max and min. There
are no point in yielding a value multiple times.

If my understanding is correct that this code is for computing the
bounding box after transformation, should not this be changed as
follows?

diff --git a/rasterio/features.py b/rasterio/features.py
index 768f6429..e0764e63 100644
--- a/rasterio/features.py
+++ b/rasterio/features.py
@@ -451,12 +451,12 @@ def geometry_window(
xs = [
x
for (left, bottom, right, top) in all_bounds
]
ys = [
y
for (left, bottom, right, top) in all_bounds
]

rows1, cols1 = rowcol(

Shinji Suzuki

Oops, I overlooked the fact that min/max was computed after (x,y) gets
transformed.

On Wed, Aug 18, 2021 at 2:22 AM Shinji Suzuki via groups.io
<shinji.suzuki=gmail.com@groups.io> wrote:

Hi.
later get transformed.
https://github.com/mapbox/rasterio/blob/master/rasterio/features.py#L451

What I don't understand are;
that should be related to 'bottom'?
2. Same value is computed twice.(e.g. left - pad_x). Since the
computed values are used later only for obtaining max and min. There
are no point in yielding a value multiple times.

If my understanding is correct that this code is for computing the
bounding box after transformation, should not this be changed as
follows?

diff --git a/rasterio/features.py b/rasterio/features.py
index 768f6429..e0764e63 100644
--- a/rasterio/features.py
+++ b/rasterio/features.py
@@ -451,12 +451,12 @@ def geometry_window(
xs = [
x
for (left, bottom, right, top) in all_bounds
]
ys = [
y
for (left, bottom, right, top) in all_bounds
]

rows1, cols1 = rowcol(

Sean Gillies

Hi,

On Tue, Aug 17, 2021 at 11:35 AM Shinji Suzuki <shinji.suzuki@...> wrote:
Oops, I overlooked the fact that min/max was computed after (x,y) gets
transformed.

On Wed, Aug 18, 2021 at 2:22 AM Shinji Suzuki via groups.io
<shinji.suzuki=gmail.com@groups.io> wrote:
>
> Hi.
> Starting this line, bounds extended by (pad_x, pad_y) are computed and
> later get transformed.
> https://github.com/mapbox/rasterio/blob/master/rasterio/features.py#L451
>
> What  I don't understand are;
> 1. 'pad_x' is subtracted from 'bottom'. Shouldn't 'pad_y' be the one
> that should be related to 'bottom'?
> 2. Same value is computed twice.(e.g. left - pad_x). Since the
> computed values are used later only for obtaining max and min. There
> are no point in yielding a value multiple times.
>
> If my understanding is correct that this code is for computing the
> bounding box after transformation, should not this be changed as
> follows?
>
> diff --git a/rasterio/features.py b/rasterio/features.py
> index 768f6429..e0764e63 100644
> --- a/rasterio/features.py
> +++ b/rasterio/features.py
> @@ -451,12 +451,12 @@ def geometry_window(
>      xs = [
>          x
>          for (left, bottom, right, top) in all_bounds
>      ]
>      ys = [
>          y
>          for (left, bottom, right, top) in all_bounds
>      ]
>
>      rows1, cols1 = rowcol(
>