Hi,
I am trying to extract the rasters by mask in batches using Python in ArcGIS 10.3. When I extracted one sample raster data by mask using the Extract by Mask tool in ArcToolbox, the result is what I expected. But I have too much raster data to extracted one by one, so I used this code to achieve it:
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "E:/MGH_data/MGH_newLandsat/Bulk Order 1043142/NDVI_TIFF"
rasterList = arcpy.ListRasters("*","tif")
output_path = "E:/MGH_data/MGH_newLandsat/Bulk Order 1043142/NDVI_Clip/"
inMaskData = "F:/MsAcademicPaper/MaGuiHe_HJL/MGH_huangjingling/basin_area.shp"
for raster in rasterList:
print raster
inRaster = raster
outExtractByMask = ExtractByMask(inRaster, inMaskData)
outname = output_path + inRaster
outExtractByMask.save(outname)
when I execute the above commands in Python window, there are some abnormal values in the nodata area in the results. Here is the value range of the result with abnormal values (the low value):
So I was wondering which step is wrong. So I tried to use this code to extract one sample raster data, and I just ran the code only before saving the output, which means it will not to execute the code that is used to save the output (the last two lines of the code), and the result is correct, without any abnormal values. Here is the value range of the correct raster result:
So I guess the problem is from the Save output raster step. But I checked the code many times and still have no idea to solve it. Anybody knows what's going wrong? I do appreciate your help.
Thanks!