Select to view content in your preferred language

Batch convert NetCDF to raster

326
0
10-20-2022 12:26 PM
Labels (1)
KristenCa
New Contributor

Hello, I am new to python and netcdf files and am trying to batch convert a bunch of netcdf files to rasters. When I run it only the last file in the folder seems to be being converted and copied. Here is the script I am using:

 

 

import arcpy
import arcpy as ap
from arcpy import env
from arcpy.sa import*

arcpy.env.workspace = "C:/Users/sutor/Desktop/KC_Trial"
arcpy.env.overwriteOutput = True
OutputFolder = "C:/Users/Desktop/KC_Trial"
NCfiles = arcpy.ListFiles("*.nc")

for filename in NCfiles:
print ("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "/" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "cdf_KC"
outRaster = OutputFolder + "/" + fileroot

arcpy.MakeNetCDFRasterLayer_md(inNCfiles, "", "x", "y", TempLayerFile, "", "", "BY_VALUE")
arcpy.CopyRaster_management(TempLayerFile, outRaster + ".tif", "", "", "", "NONE", "NONE", "")

 

 

any ideas how to loop through the entire folder?

0 Kudos
0 Replies