如何使用R将坐标系放入NetCDF?

时间:2019-03-08 22:14:53

标签: r arcgis netcdf4

我一直在使用Daymet的NetCDF文件,我的项目涉及从各种文件中提取数据,对其进行修改并在R中创建新文件,然后在Arcmaps中对其进行分析。将make NetCDF栅格图层工具与x和y一起使用,因为尺寸可以很好地处理当天的未修改数据,但对我自己制作的文件没有任何作用。使用坐标变量对它们两者均有效,但是产品失真。查看我创建的文件之间的差异,唯一的区别是我创建的文件没有任何空间参考坐标。

在未修改的文件中存在一个现有的空间参考或投影,看起来像在元数据中一样:

  

'    5个变量(不包括尺寸变量):
          float time_bnds [nv,time]
              时间:自1980-01-01 00:00:00 UTC以来的天数

     

'   简短的lambert_conformal_conic []
              grid_mapping_name:lambert_conformal_conic
              longitude_of_central_meridian:-100
              latitude_of_projection_origin:42.5
              false_easting:0
              false_northing:0
              standard_parallel:25
               standard_parallel:60
              semi_major_axis:6378137
              inverse_flattening:298.257232666016

使用netcdf r包可以创建类似于以下代码的内容:

  

'   corddef <-ncvar_def(“ lambert_conformal_conic”,“”,list(),prec =“ short”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ grid_mapping_name”,“ lambert_conformal_conic”)   ncatt_put(ncout,“ lambert_conformal_conic”,“经度”,“-100”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ latitude_of_projection_origin”,“ 42.5”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ false_easting”,“ 0”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ false_northing”,“ 0”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ standard_parallel”,“ 25”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ standard_parallel_2”,“ 60”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ semi_major_axis”,“ 6378137”)   ncatt_put(ncout,“ lambert_conformal_conic”,“ inverse_flattening”,“ 298.257232666016”)

哪个给这个:

  

'   5个变量(不包括尺寸变量):
          float time_bnds [time](Chunking:[1])
              单位:自1980-01-01 00:00:00 UTC
起的天数    短lambert_conformal_conic [](连续存储)
              grid_mapping_name:lambert_conformal_conic
              longitude_of_central_meridian:-100
              latitude_of_projection_origin:42.5
              false_easting:0
              false_northing:0
              standard_parallel:25
              standard_parallel_2:60
              semi_major_axis:6378137
              inverse_flattening:298.257232666016

尽管尝试在Arcmaps中制作栅格仍然没有任何效果,所以我想知道是否有更好的方法将有关投影的信息直接放入正在创建的新文件中,以便Arcmaps可以自动读取信息。

1 个答案:

答案 0 :(得分:0)

必须像这样完成代码,为您要添加的数字分配一个名称。

longitude_of_central_meridian <- -100
latitude_of_projection_origin <- 42.5
false_easting <- 0
false_northing <- 0
semi_major_axis <- 6378137
inverse_flattening <- 298.257232666016

ncatt_put(ncout, "lambert_conformal_conic", "grid_mapping_name", "lambert_conformal_conic")
ncatt_put(ncout,"lambert_conformal_conic","longitude_of_central_meridian", longitude_of_central_meridian)
ncatt_put(ncout,"lambert_conformal_conic","latitude_of_projection_origin", latitude_of_projection_origin)
ncatt_put(ncout,"lambert_conformal_conic","false_easting", false_easting)
ncatt_put(ncout,"lambert_conformal_conic","false_northing", false_northing)
ncatt_put(ncout,"lambert_conformal_conic", "standard_parallel", c(25,60))
ncatt_put(ncout,"lambert_conformal_conic","semi_major_axis", semi_major_axis)
ncatt_put(ncout,"lambert_conformal_conic","inverse_flattening", inverse_flattening)