The nature of what I am doing is GIS based, by my problem is python based which is why I am posting here.
I have 4 folders which contain raster files (.tif files). I am running an operation on them and then saving the output to a specific location. This is where my problem is, specifying my output path.
The code I am using is as follows:
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")
so I want my output path to by the combination of the initial outpath
and the name of the files in ndvi
. When I print outpath
though it starts by saving to the first file name, then the second file is saved to the first file name AND the second filename. So output one would be file1.tif, output two is file1.tiffile2.tif and output three is file1.tiffile2.tiffile3.tif etc.
How do I just save to the corresponding filenames in ndvi
rather than it using iteration to keep adding the names on?
Simply reset outpath before adding something again.
#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")