如何使用shapefile从netcdf文件中提取变量数据?

时间:2019-04-03 20:44:17

标签: r shapefile netcdf masking

我没有获得用于遮罩R中netcdf文件的shapefile的“ lat”和“ long”值。

以下是数据链接:https://drive.google.com/file/d/15Feww0VvEq9SuJ4j4gxuVqvxpp_w8PVC/view?usp=sharing

我在R中同时读取了netcdf和我感兴趣的区域shapefile。我转换了shapefile投影以匹配netcdf文件的投影。我用shapefile边界遮罩了netcdf文件。我将变量值写入一个csv文件。虽然,我获得了整个时间段的数据,但是,我看不到网格点的经度和纬度值。请提出前进的方向。谢谢

library(ncdf4)
library(ncdf4.helpers)
library(PCICt)
library(rgdal)
NC = brick("Daily_Pr_Inmm_Souris_1979_2016.nc")
SHP=readOGR("Souris_basin.shp")
crs(NC)
crs(SHP)
SHP=spTransform(SHP, crs(NC))
Souris_Pr_Daily=mask(NC, SHP)
tab=as.data.frame(na.omit(Souris_Pr_Daily[],xy=TRUE))
write.csv(tab, "Souris.csv")

我应该在csv文件中看到类似的内容,其中Var 1和Var 2分别代表long和lat,其余代表整个时间段内的数据

    Var1            Var2       X1            X2           Xn
1   -104.6875   47.8125 4.320732594 1.342601776    --------
2   -104.5625   47.8125 4.630135059 2.880001545    --------
3   -104.4375   47.8125 3.533707142 0.539954007    --------

0 个答案:

没有答案