首页 > 代码库 > arcgis中转换netCDF为栅格数据

arcgis中转换netCDF为栅格数据

最近有个同学询问我一个问题,使用arcpy把netcdf转化成栅格文件,忙活了两个小时才搞定,其实主要代码非常简单,只不过要对arcgis 的功能比较熟悉(其实多思考和查考它的帮助文章,无聊)

 

# -*- coding: utf-8 -*-
import arcpy
from arcpy.sa import *


def NetCDF2Tiff(inNetCDFFile,toTIFFFile):

    variable = "Qs_GDS0_SFC"
    XDimension = "g0_lon_1"
    YDimension = "g0_lat_0"
    outRasterLayer = "gldasTest"
    bandDimmension = ""
    dimensionValues = ""
    valueSelectionMethod = ""

    print "start"
    arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension,
                                   outRasterLayer, bandDimmension, dimensionValues, 
                                   valueSelectionMethod)
    arcpy.CopyRaster_management(outRasterLayer, toTIFFFile,format="TIFF")

    print "finish"


## 

inNetCDFFile = "C:/Users/Administrator/Documents/GLDAS_NOAH025SUBP_3H.A2014058.0600.001.2017040053742.pss.nc"
toTIFFFile =  "C:/Users/Administrator/Documents/test.tif"

NetCDF2Tiff(inNetCDFFile,toTIFFFile)

还有,值得注意的是,在使用arcpy的时候,使用ipython和notebook的时候,总是运行程序的时候出现错误

arcgis中转换netCDF为栅格数据