I'm trying to use Rasterio to crop all of the images within a folder. I can crop 1 image individually, but I can't embed/nest my 'with' statement after my 'for' statement so that I can run through a list of file paths - I'd really appreciate any pointers with where I am going wrong with this!
TRAIN_PATH = '/Users/Google Drive/IMG_DATA/Train/'
names = os.listdir(TRAIN_PATH)
all_paths = []
for fn in names:
all_paths.append(os.path.join(TRAIN_PATH, fn))
I've tried:
for f in all_paths:
with rasterio.open(f) as src:
out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
out_meta = src.meta
and
for f in all_paths:
src = rio.open(f)
out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
out_meta = src.meta
But get the same error message of:
' not recognized as a supported file format.
I'm using Pycharm 2021.1.1 (if that makes any difference) and I've omitted the rest of the code which actually crops the images since its the 'with' statement which is causing the issue.