def clip(self):
"""
This function clips the mosaicked, projected images to the size of the
referenceImage
"""
subprocess.call(['gdaltindex', self.extent, self.referenceImagePath])
dataNames = sorted(glob.glob(self.fullPath + '/full*.tif'))
splitAt = len(self.fullPath) + 1
for i in range(len(dataNames)):
x = dataNames[i]
y = dataNames[i][:splitAt] + dataNames[i][splitAt+4:]
subprocess.call(['gdalwarp', '-r', 'near', '-cutline', self.extent, '-crop_to_cutline', x, y, '-dstnodata', '9999'])
for n in dataNames:
os.remove(n)
dataNames = sorted(glob.glob(self.fullPath + '/*.tif'))
test = gdal.Open(dataNames[0]).ReadAsArray()
logger.log('SUCCESS', 'Clipping complete! %d %s files were successfully clipped to the size of %s with dimensions %d rows by %d columns' % (len(dataNames), str(self.outformat), str(self.referenceImagePath), test.shape[0], test.shape[1]))
评论列表
文章目录