我正在做的事情是基于GIS的,我的问题是基于python的,这就是我在这里发帖的原因。
我有4个文件夹,其中包含光栅文件(.tif文件)。我正在对它们运行操作,然后将输出保存到特定位置。这是我的问题所在,指定我的输出路径。
我使用的代码如下:
import arcpy
from arcpy.sa import *
#set pathway to rasters
arcpy.env.workspace=r'F:\Sheyenne\Normalized_Indices\Fuzzy_Overlay\NDVI'
NDVIraster=arcpy.ListRasters('*tif')
arcpy.env.workspace=r'F:\Sheyenne\Normalized_Indices\Fuzzy_Overlay\NDII'
NDIIraster=arcpy.ListRasters('*tif')
arcpy.env.workspace=r'F:\Sheyenne\Normalized_Indices\Fuzzy_Overlay\RGR'
RGRraster=arcpy.ListRasters('*tif')
arcpy.env.workspace=r'F:\Sheyenne\Normalized_Indices\Fuzzy_Overlay\SWIR32'
SWIR32raster=arcpy.ListRasters('*tif')
#set the output pathway
outpath='F:\Sheyenne\Normalized_Indices\Fuzzy_Membership\\'
#run my operation
for ndvi, ndii, rgr, swir32, in zip(NDVIraster, NDIIraster,RGRraster, SWIR32raster):
outpath=outpath + ndvi
outraster= arcpy.gp.FuzzyOverlay_sa([ndvi, ndii, rgr, swir32], outpath, "AND")
所以我希望通过初始outpath
和ndvi
中文件名的组合来输出路径。当我打印outpath
虽然它首先保存到第一个文件名,然后第二个文件保存到第一个文件名和第二个文件名。因此输出一个是file1.tif,输出二是file1.tiffile2.tif,输出三个是file1.tiffile2.tiffile3.tif等。
如何保存ndvi
中的相应文件名而不是使用迭代来继续添加名称?
答案 0 :(得分:1)
只需在重新添加内容之前重置路径。
#run my operation
for ndvi, ndii, rgr, swir32, in zip(NDVIraster, NDIIraster,RGRraster,SWIR32raster):
outpath='F:\Sheyenne\Normalized_Indices\Fuzzy_Membership\\'
outpath=outpath + ndvi
outraster= arcpy.gp.FuzzyOverlay_sa([ndvi, ndii, rgr, swir32], outpath, "AND")
答案 1 :(得分:0)
您正在覆盖outpath
变量。您需要使用2个变量来按照您的方式工作,例如使用outpath_base
作为根。
#set the output pathway
outpath_base='F:\Sheyenne\Normalized_Indices\Fuzzy_Membership\\'
#run my operation
for ndvi, ndii, rgr, swir32, in zip(NDVIraster, NDIIraster,RGRraster, SWIR32raster):
outpath=outpath_base + ndvi
outraster= arcpy.gp.FuzzyOverlay_sa([ndvi, ndii, rgr, swir32], outpath, "AND")