我处理Sentinel2图像,并试图重新整理它们。
我尝试了以下代码:
import os, fnmatch
INPUT_FOLDER = "/d/afavro/Bureau/test_resampling/original"
OUTPUT_FOLDER = "/d/afavro/Bureau/test_resampling/resampling_10m"
def findRasters (path, filter):
for root, dirs, files in os.walk(path):
for file in fnmatch.filter(files, filter):
yield file
for raster in findRasters(INPUT_FOLDER,'*.tif'):
print(raster)
inRaster = INPUT_FOLDER + '/' + raster
print(inRaster)
outRaster = OUTPUT_FOLDER + '/resample' + raster
print (outRaster)
cmd = "gdalwarp -tr 10 10 -r cubic " % (inRaster,outRaster)
os.system(cmd)但我仍然收到同样的错误信息:
def findRasters (path, filter): ^
IndentationError: unexpected indent我已经尝试过使用相同类型的代码来生成子集,并且成功了。我不明白我的错误是怎么来的。
发布于 2019-04-24 11:40:55
错误类型IndentationError应该从字面上看:您的缩进似乎是错误的。你的线路
def findRasters (path, filter):缩进太远,但需要与前面的行处于相同的缩进级别。
OUTPUT_FOLDER = "/d/afavro/Bureau/test_resampling/resampling_10m"您提供的完整代码示例应该如下所示:
import os, fnmatch
INPUT_FOLDER = "/d/afavro/Bureau/test_resampling/original"
OUTPUT_FOLDER = "/d/afavro/Bureau/test_resampling/resampling_10m"
def findRasters (path, filter):
for root, dirs, files in os.walk(path):
for file in fnmatch.filter(files, filter):
yield file
for raster in findRasters(INPUT_FOLDER,'*.tif'):
print(raster)
inRaster = INPUT_FOLDER + '/' + raster
print(inRaster)
outRaster = OUTPUT_FOLDER + '/resample' + raster
print (outRaster)
cmd = "gdalwarp -tr 10 10 -r cubic " % (inRaster,outRaster)
os.system(cmd)另外,正如您在附加注释中所写的,您的行
cmd = "gdalwarp -tr 10 10 -r cubic " % (inRaster,outRaster)似乎是错误的,因为inRaster和outRaster不会在字符串中使用。使用字符串格式代替:
cmd = 'gdalwarp -tr 10 10 -r cubic "{}" "{}"'.format(inRaster, outRaster)https://stackoverflow.com/questions/55829171
复制相似问题