I am trying to crop the TIF images based on the shape file. After searching the web, I found the following code and manipulated it.
from osgeo import gdal
import os
input_path = '/.../pics'
output_path = '/.../clipped_pics/'
bandList = [band for band in os.listdir(input_path) if band[-4:]=='.tif']
shp_clip = '/.../Index.shp'
for band in bandList:
print(output_path + band[:-4]+'_c2'+band[-4:])
options = gdal.WarpOptions(cutlineDSName=shp_clip,cropToCutline=True)
outBand = gdal.Warp(srcDSOrSrcDSTab=input_path + band,
destNameOrDestDS=output_path + band[:-4]+'_c2'+band[-4:],
options=options)
outBand= None
However, this is the error I get:
TypeError Traceback (most recent call last)
<ipython-input-51-e2d9d6412405> in <module>
4 outBand = gdal.Warp(srcDSOrSrcDSTab=input_path + band,
5 destNameOrDestDS=output_path + band[:-4]+'_c2'+band[-4:],
----> 6 options=options)
7 outBand= None
~/opt/anaconda3/lib/python3.7/site-packages/osgeo/gdal.py in Warp(destNameOrDestDS, srcDSOrSrcDSTab, **kwargs)
673
674 if _is_str_or_unicode(destNameOrDestDS):
--> 675 return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
676 else:
677 return wrapper_GDALWarpDestDS(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
~/opt/anaconda3/lib/python3.7/site-packages/osgeo/gdal.py in wrapper_GDALWarpDestName(args)
4315 def wrapper_GDALWarpDestName(args):
4316 """wrapper_GDALWarpDestName(char const * dest, int object_list_count, GDALWarpAppOptions warpAppOptions, GDALProgressFunc callback=0, void * callback_data=None) -> Dataset"""
-> 4317 return _gdal.wrapper_GDALWarpDestName(*args)
4318 class GDALVectorTranslateOptions(_object):
4319 """Proxy of C++ GDALVectorTranslateOptions class."""
TypeError: object of wrong GDALDatasetShadow