Re: window from_bounds behaviour

Dion Häfner
 

Hey Tom,

rasterio windows are constructed at a specific resolution, so you need to supply a transform to use. It is usually easiest to use the transform of the raster you want to use the window on.

So something like this should work:

import rasterio, rasterio.windows
with rasterio.open('myraster.tif') as src:
... window = rasterio.windows.from_bounds(
... -150, 40, -45, 90, transform=src.transform
... )
... data = src.read(window=window)

Hope that helps.

Dion


On 08/01/2020 23.49, Tom Kralidis via Groups.Io wrote:
Hi all: first off, kudos to the rasterio project, very well done!
Using 1.1.2 I'm getting some weird behaviour when trying to create a window from bounding coordinates.
|>>> from rasterio.windows import from_bounds >>> window = from_bounds(-150, 40, -45, 90) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/tomkralidis/Dev/pygeoapi/lib/python3.7/site-packages/rasterio/windows.py", line 278, in from_bounds transform, left, top, op=float, precision=precision) File "/Users/tomkralidis/Dev/pygeoapi/lib/python3.7/site-packages/rasterio/transform.py", line 238, in rowcol invtransform = ~transform TypeError: bad operand type for unary ~: 'NoneType' |
Any idea what I am doing wrong here?
Thanks
..Tom
P.S. aside: The pygeoapi <https://pygeoapi.io> project is implementing the OGC API - Coverages specification and will be using rasterio as the default coverage provider.

Join main@rasterio.groups.io to automatically receive all group messages.