terra
パッケージを使用して、ラスター スタックから抽出した値を Spatial オブジェクトの data.frame に追加したい
f <- system.file("ex/logo.tif", package="terra")
r <- rast(f)
#Plot the raster
plot(r, 1:3)
#Create a vector file
points <- cbind.data.frame(Longitude = 40, Latitude = 40, val = 0.5)
points <- rbind.data.frame(points-1, points, points+1)
points_vect <- vect(points, geom=c("Longitude", "Latitude"), crs=crs(r, proj=T),
type = "points")
#Extract the values from raster using the point vector
terra::extract(r, points_vect, xy = T, method = "simple")
#> ID red green blue x y
#> 1 1 255 255 253 30 30
#> 2 2 149 159 186 40 40
#> 3 3 146 156 207 50 50
出力ファイルからわかるように、以前はパッケージの引数val
を使用して取得していたものはありません。抽出されたdata.frameにフィールドを追加するにはどうすればよいですか?sp
raster
val