I'm using rasterio.mask.mask to mask a raster with a shapefile.

import rasterio
import fiona

image_object = rasterio.open('/home/cate/image_name.img')

aoi_shapefile = fiona.open('/home/cate/AOI.shp', "r")
aoi = [polygon["geometry"] for polygon in aoi_shapefile]

image_aoi, image_aoi_transform = rasterio.mask.mask(image_object, aoi)

and I get UserWarning: shapes are outside bounds of raster. Are they in different coordinate reference systems?

As far as I can tell the shape is definitely within the raster bounds..

BoundingBox(left=117.4095061135422, bottom=33.73209332058161, right=120.49755473423146, top=35.64128279392083)

(119.82677788035676, 34.076577156414714, 120.37042708436398, 34.575927115244426)

CRS({'init': 'epsg:4326'})

{'init': 'epsg:4326'}

Here is the view in QGIS: enter image description here

I'm using rasterio 1.0a10 - any ideas what is happening here?

  • Hi Cate, I've tried to simulate this in a test I've added to the Rasterio test suite: github.com/mapbox/rasterio/pull/1213/… and am unable to reproduce the problem. Can you share the .img and .shp files by any chance? – sgillies Nov 29 '17 at 18:08
  • Cate, I actually have seen a similar issue in 1.0a10 in Windows, installed with conda, but haven't yet dug into it enough to file a clear bug report. I'd be curious though if you see the same behavior with 1.0a9 (I do not see this in 1.0a9). – jdmcbr Nov 30 '17 at 4:18
  • @sgillies - no problem, the .img are shape are here drive.google.com/open?id=1e8E4ShLai283XbcRDuXlSSXhcfiPpolZ – Cate Nov 30 '17 at 12:23
  • @jdmcbr - just rerun the same in a fresh environment (installed with pip on Ubuntu) with 1.0a9 and did NOT get the warning, mask returned a masked array as expected. I have also repeated the preprocessing of the satellite image and no errors are apparent with the original .img file. – Cate Nov 30 '17 at 12:27

Cate, this is a rasterio bug that is fixed in version 1.0a12 (on PyPI now).

pip install --pre -U rasterio

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.