如何使用多个字段值进行栅格化?

时间:2021-07-02 15:24:32

标签: r terra

如何在光栅化过程中在字段中包含多个字符向量?

sum.v <- vect(summer_values, geom=c("X","Y"), crs="epsg:4326")
sum.v <- terra::project(sum.v, sun.rast)

sum.v_2009 <-sum.v%>%
terra::rasterize(sun.rast, c("Summer_2009", "Summer_2010"))

names(sum.v)
 [1] "Summer_2009"    "Summer_2010"    "Summer_2011"    "Summer_2012"   
 [5] "Summer_2013"    "Summer_2014"    "Summer_2015"    "Summer_2016"   
 [9] "Summer_2017"    "Summer_2018"    "Summer_2019"    "Coastal_Cities"

SpatRaster 数据:

sun.rast
class       : SpatRaster 
dimensions  : 290, 180, 11  (nrow, ncol, nlyr)
resolution  : 5000, 5000  (x, y)
extent      : -2e+05, 7e+05, -2e+05, 1250000  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +a=6377563.396 +rf=299.324961266495 +units=m +no_defs 
sources     : sun_hadukgrid_uk_5km_seas_200901-200912.nc  
              sun_hadukgrid_uk_5km_seas_201001-201012.nc  
              sun_hadukgrid_uk_5km_seas_201101-201112.nc  
              ... and 8 more source(s)
varnames    : sun (Sunshine hours) 
              sun (Sunshine hours) 
              sun (Sunshine hours) 
              ...
names       : sun_3, sun_3, sun_3, sun_3, sun_3, sun_3, ... 
unit        :  hour,  hour,  hour,  hour,  hour,  hour, ... 
time        : 2009-07-17 to 2019-07-17 
<块引用>

警告信息: 在 if (field != "") { : 条件的长度 > 1 并且只使用第一个元素

一些代码:

summer_values <- structure(list(Summer_2009 = c(501.574778416789, 497.23728360199, 
497.61686652504, 490.152801533259, 487.926624123223), Summer_2010 = c(552.15358001888, 
539.422481406991, 544.592473937123, 531.067001849623, 526.872958713714
), Summer_2011 = c(466.172979620426, 455.343068520793, 458.47881616961, 
446.66203650141, 443.013987031318), Summer_2012 = c(415.175042208515, 
408.956046115294, 411.354325261626, 403.962524048422, 402.260345730052
), Summer_2013 = c(631.57123174756, 622.029331693976, 626.041896670884, 
613.490126706086, 608.51521408192), Summer_2014 = c(665.070703822075, 
659.84212560111, 663.501153102094, 654.769857459827, 650.633495190551
), Summer_2015 = c(487.113946360211, 477.18082182742, 479.267886683776, 
467.824113810407, 463.960603587997), Summer_2016 = c(474.592225824081, 
466.145013452213, 469.399319785728, 458.943733828422, 454.994896176023
), Summer_2017 = c(498.34924661133, 494.588099225139, 494.926318646358, 
488.53166390283, 486.521775155493), Summer_2018 = c(639.152209854641, 
628.982562423085, 631.774207608961, 618.636603897715, 614.462182951034
), Summer_2019 = c(561.763428056815, 563.985839571988, 562.998859621631, 
561.595114701102, 561.461548754331), X = c(377500, 382500, 377500, 
382500, 387500), Y = c(127500, 127500, 122500, 122500, 122500
), Coastal_Cities = c("Dorset", "Dorset", "Dorset", "Dorset", 
"Dorset")), row.names = c(NA, 5L), class = "data.frame")

0 个答案:

没有答案