NameError: name 'Window' is not defined


quinsen.joel@...
 

Hello. I'm new to this forum, so let me know if there are any problems with my question here.

I am trying to use rasterio's windowed reading ability and I am hoping to use the following structure as shown on rasterios documentation page (https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html):
 
 
```
with rasterio.open('file.tif') as src:
   window = src.read(1, window=Window(0, 0, new_height, new_width)) 
```
 
 
However, when I try to do this I get:
 
```NameError: name 'Window' is not defined```
 
Shouldn't Window() be imported with rasterio? Is this a problem with the version of rasterio I have downloaded or am I missing something really easy here?
 
```
print (rasterio.__version__)
1.0.7
```
 
Thank you for your guidance,
Quin


Sean Gillies
 

Hi Quin,

The Window class is defined in the rasterio.windows module and you must explicitly import it into your program's code like this:

    from rasterio.windows import Window

Example code in our docs might obscure this need, if you see any docs that don't show import of the Window class, let me know and I'll fix them.

On Mon, May 6, 2019 at 1:23 PM <quinsen.joel@...> wrote:
Hello. I'm new to this forum, so let me know if there are any problems with my question here.

I am trying to use rasterio's windowed reading ability and I am hoping to use the following structure as shown on rasterios documentation page (https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html):
 
 
```
with rasterio.open('file.tif') as src:
   window = src.read(1, window=Window(0, 0, new_height, new_width)) 
```
 
 
However, when I try to do this I get:
 
```NameError: name 'Window' is not defined```
 
Shouldn't Window() be imported with rasterio? Is this a problem with the version of rasterio I have downloaded or am I missing something really easy here?
 
```
print (rasterio.__version__)
1.0.7
```
 
Thank you for your guidance,
Quin



--
Sean Gillies


debboutr@...
 

you just need the class in your namespace, try:

`from rasterio.windows import Window`

I would agree it's not easy from the docs to know where to go and find this.

cheers

 

~rickD


Sean Gillies
 

Thanks for the help, rickD!

In https://github.com/mapbox/rasterio/commit/eebf54b74fa0f718cb8baaa44aa20616e405b4e4 I added the missing Window class import. Read the Docs should be updated in a couple minutes. I think this should help.


On Mon, May 6, 2019 at 1:38 PM <debboutr@...> wrote:

you just need the class in your namespace, try:

`from rasterio.windows import Window`

I would agree it's not easy from the docs to know where to go and find this.

cheers

 

~rickD



--
Sean Gillies


quinsen.joel@...
 

Thanks for both your help! I see the import statement in the docs now, cheers!

-Quin