R语言_气象数据提取

本文中的气象数据来源于Worldclim 2.0 2.5M数据集,自行搜索下载

1)1970-2020月平均降雨量

读取2.5M 降雨数据,Worldclim 2.0提供的是栅格化气候数据(.tif文件)
> library(raster)
> dir("E:/GIS/WorldClim/precipitation",full.names = T) %>% 
+   stack() -> worldclimtemp
> worldclimtemp
class      : RasterStack 
dimensions : 4320, 8640, 37324800, 12  (nrow, ncol, ncell, nlayers)
resolution : 0.04166667, 0.04166667  (x, y)
extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
names      : wc2.1_2.5m_prec_1, wc2.1_2.5m_prec_10, wc2.1_2.5m_prec_11, wc2.1_2.5m_prec_12, wc2.1_2.5m_prec_2, wc2.1_2.5m_prec_3, wc2.1_2.5m_prec_4, wc2.1_2.5m_prec_5, wc2.1_2.5m_prec_6, wc2.1_2.5m_prec_7, wc2.1_2.5m_prec_8, wc2.1_2.5m_prec_9 
min values :                 0,                  0,                  0,                  0,                 0,                 0,                 0,                 0,                 0,                 0,                 0,                 0 
max values :               943,               2342,                755,                834,              1007,               878,              1010,              2077,              2226,              2768,              2027,              1968 

> plot(worldclimtemp)

Rplot38.jpeg

2)提取省会城市月平均降雨量

# 首先,获取城市经纬度
> library(sf)
> cities <- readOGR("E:/GIS/四百万数据/省会城市.shp")
> china <- readOGR("E:/GIS/四百万数据/中国界.shp")
> citiesLL <- data.frame(longitude = coordinates(cities)[,1],
                         latitude = coordinates(cities)[,2])
> head(citiesLL)
  longitude latitude
1  116.3809 39.92361
2  117.2035 39.13112
3  114.4898 38.04513
4  112.5694 37.87111
5  111.6633 40.82094
6  123.4117 41.79662


# refs:
# https://qa.1r1g.com/sf/ask/2081560421/

# 其次,根据经纬度提取降雨量数据
> site = cities$PINYIN
> Chinacity <- raster::extract(worldclimtemp, citiesLL)
> Chinacity2 <- Chinacity %>% 
+   as_tibble() %>% 
+   add_column(Site = site, .before = "Jan")
> head(Chinacity2)
# A tibble: 6 x 13
  Site           Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
  <chr>        <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Beijing          5     4    10    16    31    74   201   154    45    17     7     5
2 Tianjin          8     4     9    18    29    67   207   153    41    16    11     9
3 Shijiazhuang     5     8    11    21    33    51   145   144    51    26    18     6
4 Taiyuan          4     6    13    21    32    53   109   107    52    25    14     5
5 Huhehaote        5     3     6     9    21    32    79    84    33    16     6     4
6 Shenyang         6     7    16    38    55    91   173   154    79    43    19     9

3)全国月平均降雨量

> Chinatemp <- china %>% crop(worldclimtemp, .)
> exactChina <- mask(Chinatemp, china)   
> plot(exactChina)
Rplot39.jpeg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容