-1

I've been combing stack exchange and I cannot figure it out. I have a raster "slope_tif_18TXK030910", I want to reclassify it, rename it and put it into a new folder. this is what I have and it works fine BUT it comes out just named "reclass_" instead of "reclass_slope_tif_18TXK030910"

# Import system modules
import arcpy
from arcpy import env
import os
from arcpy.sa import *

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")


inputFolder = r'E:\BLSK_HSI\practice_fish'
env.workspace = inputFolder
outputFolder = r'E:\BLSK_HSI\practiceLC'

inRaster = r'E:\BLSK_HSI\practice_fish\slope_tif_18TXK030910.img'
reclassField = "VALUE"
remap = RemapValue([[-1, 20, 1], [21, 90, 2]])
outReclassify = Reclassify(inRaster, reclassField, remap, "NODATA")
outname = os.path.join(outputFolder, "reclass_"+".img")
outReclassify.save(outname)
2

It looks like you need to pull out the name of the file from "inRaster" and add it into your "outname" variable. I've copied your last block of code and added comments to the lines I've added/edited. If the rest of your code is working as you indicate, this should take care of fixing the name and writing it where you want it.

inRaster = r'E:\BLSK_HSI\practice_fish\slope_tif_18TXK030910.img'
basename = os.path.basename(inRaster)  # pull out everything after the last directory
reclassField = "VALUE"
remap = RemapValue([[-1, 20, 1], [21, 90, 2]])
outReclassify = Reclassify(inRaster, reclassField, remap, "NODATA")
outname = os.path.join(outputFolder, "reclass_"+basename)  # basename keeps extensions
outReclassify.save(outname)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.