POST
|
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:\prec"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:\prec\Raster"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "/" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "prec_amount"
outRaster = OutputFolder + "/" + fileroot
# Process: Make NetCDF Raster Layer
# this will convert the FIRST time step in your netCDF file to a raster layer
arcpy.MakeNetCDFRasterLayer_md(filename, "prec", "lon", "lat", TempLayerFile, "#", "time 01/01/2000 12:00:00 PM", "BY_VALUE")
# Process: Copy Raster
arcpy.CopyRaster_management(TempLayerFile, outRaster + ".tif", "", "", "", "NONE", "NONE", "")
print "***DONE!!!"
print arcpy.GetMessages()
Thanks Dan. I pasted the code as above. So, I have replaced inNCfiles either in both entries (i.e. lines 22 and 30) or only at line 30, but I m still getting the same error and I have no clue the reasons why. "Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\md.py", line 172, in MakeNetCDFRasterLayer raise e RuntimeError: Object: Error in executing tool"
... View more
03-24-2017
04:22 PM
|
1
|
0
|
1137
|
POST
|
Apologies guys for asking the same question.. I went through similar examples and I very unfamiliar with Phython scripts, so I tried only the most simple one first (i.e. exctrating the first raster layer): # Import system modules import arcpy from arcpy import env from arcpy.sa import * # Input data source arcpy.env.workspace = "C:\prec" arcpy.env.overwriteOutput = True # Set output folder OutputFolder = "C:\prec\Raster" # Loop through a list of files in the workspace NCfiles = arcpy.ListFiles("*.nc") for filename in NCfiles: print("Processing: " + filename) inNCfiles = arcpy.env.workspace + "/" + filename fileroot = filename[0:(len(filename)-3)] TempLayerFile = "prec_amount" outRaster = OutputFolder + "/" + fileroot # Process: Make NetCDF Raster Layer # this will convert the FIRST time step in your netCDF file to a raster layer arcpy.MakeNetCDFRasterLayer_md(inNCfiles, "prec", "lon", "lat", TempLayerFile, "#", "time 01/01/2000 12:00:00 PM", "BY_VALUE") # Process: Copy Raster arcpy.CopyRaster_management(TempLayerFile, outRaster + ".tif", "", "", "", "NONE", "NONE", "") print "***DONE!!!" print arcpy.GetMessages() The error message does not have any specific ID so I am not sure why the tool could not succeed: "Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\md.py", line 172, in MakeNetCDFRasterLayer raise e RuntimeError: Object: Error in executing tool". Would anyone have any guess?
... View more
03-24-2017
02:30 PM
|
0
|
2
|
1137
|
POST
|
I have a single NetCDF file that contains daily precipitation data for several years and would like to extract them in a more automatic way. I am aware I could do it by creating an model builder and within "make netcdf raster layer" make the dimension values variable. However when I add a quite a lot of dimension values, model builder keeps crashing. That is a print screen of my model: I am wondering if someone could help me with a phyton scripts for this. That would be very much appreciated.
... View more
03-23-2017
07:31 PM
|
0
|
5
|
2801
|
Title | Kudos | Posted |
---|---|---|
1 | 03-24-2017 04:22 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|