我正在尝试使用ArcPy脚本将多个光栅文件转换为NetCDF文件。当我运行以下脚本时,我收到以下错误消息:
Message File Name Line Position
Traceback
<module> <module1> 19
RasterToNetCDF C:\Program Files\ArcGIS\Desktop10.3\ArcPy\arcpy\md.py 253
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog.
Failed to execute (RasterToNetCDF).
Python脚本:
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = r"D:\2012A"
# Set local variables
inRaster = r"D:\2012A"
outNetCDFFile = r"D:\2012A/nppnetcdf.nc"
variable = "elevation"
units = "meter"
XDimension = "x"
YDimension = "y"
bandDimension = ""
# Process: RasterToNetCDF
arcpy.RasterToNetCDF_md(inRaster, outNetCDFFile, variable, units,
XDimension, YDimension, bandDimension)
答案 0 :(得分:0)
我遇到两个问题。
首先,此处outNetCDFFile = r"D:\2012A/nppnetcdf.nc"
的文件路径无效。两者都应该是反斜杠\
以获得有效路径。
其次,更有可能导致错误 - inRaster = r"D:\2012A"
似乎是一个目录。您不能仅将目录传递给RasterToNetCDF_md
tool - 输入参数必须是栅格图层。在光栅文件(不在目录上!)上运行MakeRasterLayer_management
tool以创建栅格图层,并将结果传递给RasterToNetCDF_md
。
答案 1 :(得分:0)
@Erica回答了您收到错误的原因,但如果要对目录中的每个栅格数据集执行转换,则必须先在其中创建栅格列表。这可以通过类似的方式完成这样:
rasterlist = arcpy.ListRasters()
## other variables, as you have already defined them in your code
for raster in rasterlist:
RastertoNetCDF_md(variables)
所以要实现这个:
# Set environment settings
env.workspace = r"D:\2012A"
# Set local variables
inRaster = r"D:\2012A"
outNetCDFFile = r"D:\2012A\nppnetcdf.nc"
variable = "elevation"
units = "meter"
XDimension = "x"
YDimension = "y"
bandDimension = ""
rasterlist = arcpy.ListerRasters()
# Process: RasterToNetCDF
for raster in rasterlist:
arcpy.RasterToNetCDF_md(inRaster, outNetCDFFile, variable, units,
XDimension, YDimension, bandDimension)