I am really new in Python programming. I try to make a loop for Extract by Attributes tool in ArcGIS 10.1. I have a huge dataset of raster (760pc) and I want to extract a specific value. This part of script runs fine. But ArcGIS in this function can only produce a GRID format with 13 characters so it changes my original names (.img file).
How can I keep the original names of rasters from my datasets?
Maybe I have to produce a list of results and convert them to .img file?
When I did it, it has kept the new generated GRID name (Extract_1), not my original name.
Anyone can help?
# Name: ExtractByAttributes_Ex_02.py
# Description: Extracts the cells of a raster based on a logical query.
# Requirements: Spatial Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = r"d:\UEL\Data\poskod_cez_VI_2\ch_msi_vci"
# Set local variables
inRaster = "ch_n_msi_00_02_10.img"
inSQLClause = "VALUE = 5"
outFolder = r"d:\UEL\Data\poskod_cez_VI_2\export_values"
#Allows overwriting
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Get a list of the rasters in the workspace
rasters = arcpy.ListRasters()
# Loop through the list of rasters
for inRaster in rasters:
# Set the outputname for each output to be the same as the input
outRaster = outFolder + "\\" + inRaster
# Process: Extract by Mask
attExtract = ExtractByAttributes(inRaster, inSQLClause)
# Save the output
attExtract.save(r"d:\UEL\Data\poskod_cez_VI_2\export_values")
attExtract.save(r"d:\UEL\Data\poskod_cez_VI_2\export_values")
toattExtract.save(r"d:\UEL\Data\poskod_cez_VI_2\export_values.img")
to output a .img.(attExtract.save(r"d:\UEL\Data\poskod_cez_VI_2\export_values.img)
convert only this one raster to .img format, not all rasters. The path:attExtract.save(r"d:\UEL\Data\poskod_cez_VI_2\export_values")
represent only a folder to store the new-generated rasters. Maybe you know the other solution?