Geographic Information Systems Asked by Yiqian Zeng on April 19, 2021
I know how to use the below python script to fill no data in a single raster using focal statistics, but I have a series of rasters, I do not want to run the script one by one.
Can any people tell me how to do it in batch?
>>>
... import arcpy
... from arcpy import env
... from arcpy.sa import *
... env.workspace = "C:/Users/wing/Desktop/try/NDVI"
... outCon = Con(Raster("MOD13Q1.A2000049.250m_16_days_NDVI.tif")<-2000, FocalStatistics("MOD13Q1.A2000049.250m_16_days_NDVI.tif",NbrRectangle(3,3),"MEAN","NODATA"), "MOD13Q1.A2000049.250m_16_days_NDVI.tif")
... outCon.save("C:/Users/wing/Desktop/try/outcon")
you can make a loop based on ListRasters in your repository. Note that your method is looking for "impossible NDVI values" (< -2000) but if you want to specifically manage NoData, then you should use "IsNull()". And if you have values below -2000, focal stat will not ignore them, so you should probably force those values to be NoData first. (e.g. with Con(myraster>-2000,myraster) )
rasters = arcpy.ListRasters("MOD*", "TIF")
for modNDVI in rasters:
inraster = Raster(modNDVI) #make a raster object from iput name
outraster = modNDVI.replace("NDVI","NDVI_filled") #set an output name
outCon = Con(IsNull(inraster), FocalStatistics(inraster,NbrRectangle(3,3),"MEAN","NODATA"), inraster)
outCon.save(outraster)
Answered by radouxju on April 19, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP