reading with a window doesn't honour window shape


Loïc Dutrieux
 

Note that setting out_shape to (1200, 1200) will likely read a (1200, 1199) shaped chunk of data and resample it to (1200, 1200); which is not exactly the same as reading a 1200*1200 window.

Kind regards,
Loïc
________________________________________
From: main@rasterio.groups.io <main@rasterio.groups.io> on behalf of Paolo Corti <pcorti@...>
Sent: 15 January 2021 20:43:21
To: main@rasterio.groups.io
Subject: Re: [rasterio] reading with a window doesn't honour window shape

Thanks Guillaume, that did the trick :)
Would also love to know the reason why that is needed.
best
Paolo

On Fri, Jan 15, 2021 at 1:53 PM Guillaume Lostis <guillaume@...<mailto:guillaume@...>> wrote:
Hi,

If you add `out_shape=(1200, 1200)` to your `read()` call it returns an array with the right shape. I don't know exactly why you need to specify this though.

Best,

Guillaume

Le ven. 15 janv. 2021 à 17:48, Paolo Corti <pcorti@...<mailto:pcorti@...>> a écrit :
Hi all

I have the following problem: I want to read a dataset using a window with a specific shape, but the window shape isn't always honored from the returned array.

You can replicate this problem using this dataset: https://www.worldpop.org/geodata/summary?id=6334<https://urldefense.com/v3/__https://www.worldpop.org/geodata/summary?id=6334__;!!DOxrgLBm!R8DE-M0LoCdGJkxHEE7d81JPP8UIGkAXjLZ_GJL5tBBF3QRGWwWHOBaSpab9fGiBA4Bpvcs$>

with rasterio.open(raster_pop_path) as src_pop:
window = Window(col_off=1470.4999917338748, row_off=2902.4961942222235, width=1200, height=1200)
pop_arr = src_pop.read(1, window=window)
print(pop_arr.shape)

print returns (1200, 1199) while it should be (1200, 1200)

Any idea why this could happen?
Thanks in advance

Paolo

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net<https://urldefense.com/v3/__http://www.paolocorti.net__;!!DOxrgLBm!R8DE-M0LoCdGJkxHEE7d81JPP8UIGkAXjLZ_GJL5tBBF3QRGWwWHOBaSpab9fGiBh8FrJuw$>
twitter: @capooti
skype: capooti
#drt3jc1


--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net<https://urldefense.com/v3/__http://www.paolocorti.net__;!!DOxrgLBm!R8DE-M0LoCdGJkxHEE7d81JPP8UIGkAXjLZ_GJL5tBBF3QRGWwWHOBaSpab9fGiBh8FrJuw$>
twitter: @capooti
skype: capooti
#drt3jc1


Paolo Corti
 

Thanks Guillaume, that did the trick :)
Would also love to know the reason why that is needed.
best
Paolo

On Fri, Jan 15, 2021 at 1:53 PM Guillaume Lostis <guillaume@...> wrote:
Hi,

If you add `out_shape=(1200, 1200)` to your `read()` call it returns an array with the right shape. I don't know exactly why you need to specify this though.

Best,

Guillaume

Le ven. 15 janv. 2021 à 17:48, Paolo Corti <pcorti@...> a écrit :
Hi all

I have the following problem: I want to read a dataset using a window with a specific shape, but the window shape isn't always honored from the returned array.

You can replicate this problem using this dataset: https://www.worldpop.org/geodata/summary?id=6334

with rasterio.open(raster_pop_path) as src_pop:
window = Window(col_off=1470.4999917338748, row_off=2902.4961942222235, width=1200, height=1200)
pop_arr = src_pop.read(1, window=window)
print(pop_arr.shape)

print returns (1200, 1199) while it should be (1200, 1200)

Any idea why this could happen?
Thanks in advance

Paolo

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti
#drt3jc1



--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti
#drt3jc1


Guillaume Lostis <guillaume@...>
 

Hi,

If you add `out_shape=(1200, 1200)` to your `read()` call it returns an array with the right shape. I don't know exactly why you need to specify this though.

Best,

Guillaume

Le ven. 15 janv. 2021 à 17:48, Paolo Corti <pcorti@...> a écrit :
Hi all

I have the following problem: I want to read a dataset using a window with a specific shape, but the window shape isn't always honored from the returned array.

You can replicate this problem using this dataset: https://www.worldpop.org/geodata/summary?id=6334

with rasterio.open(raster_pop_path) as src_pop:
window = Window(col_off=1470.4999917338748, row_off=2902.4961942222235, width=1200, height=1200)
pop_arr = src_pop.read(1, window=window)
print(pop_arr.shape)

print returns (1200, 1199) while it should be (1200, 1200)

Any idea why this could happen?
Thanks in advance

Paolo

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti
#drt3jc1


Paolo Corti
 

Hi all

I have the following problem: I want to read a dataset using a window with a specific shape, but the window shape isn't always honored from the returned array.

You can replicate this problem using this dataset: https://www.worldpop.org/geodata/summary?id=6334

with rasterio.open(raster_pop_path) as src_pop:
window = Window(col_off=1470.4999917338748, row_off=2902.4961942222235, width=1200, height=1200)
pop_arr = src_pop.read(1, window=window)
print(pop_arr.shape)

print returns (1200, 1199) while it should be (1200, 1200)

Any idea why this could happen?
Thanks in advance

Paolo

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti
#drt3jc1