向 SpatVect 添加属性:.local(x, ...) 中的错误:未使用的参数

问题描述 投票:0回答:2

使用 vect() 创建带有属性的 spatvect 时,我不断收到错误 Error in .local(x, ...):未使用的参数。当我不尝试输入属性时,它工作得很好。我不知道我哪里错了。

long_lat <- data.frame(lon = c(18.5,18.5,18.5,18.6,18.6), lat = c(-34, -33.9, -33.6,-33.6,-34))

colnames(long_lat) <- c("lon", "lat")

atts <- data.frame(imi = c(123, 0.4, 706,21,9)

#works fine
pts_jan <- vect(long_lat,  crs="+proj=longlat +datum=WGS84 +no_defs")

#error
pts_jan <- vect(long_lat,  atts = atts, crs="+proj=longlat +datum=WGS84 +no_defs")

.local(x, ...) 中的错误: 未使用的参数 (atts = list(c(123, 0.4, 706, 21, 9)))

r spatial terra
2个回答
1
投票

您可以将属性数据框与long_lat数据框绑定,然后将其转换为spatvect,如

library(terra)

long_lat <- data.frame(lon = c(18.5,18.5,18.5,18.6,18.6), 
                       lat = c(-34, -33.9, -33.6,-33.6,-34))

colnames(long_lat) <- c("lon", "lat")

atts <- data.frame(imi = c(123, 0.4, 706, 21, 9))

#Add the attribute data.frame to long_lat data.frame
long_lat <- cbind.data.frame(long_lat, atts)

#works fine
pts_jan <- vect(long_lat,  crs="+proj=longlat +datum=WGS84 +no_defs")
pts_jan 

#> class       : SpatVector 
#> geometry    : points 
#> dimensions  : 5, 2  (geometries, attributes)
#> extent      : 18.5, 18.6, -34, -33.6  (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +no_defs 
#> names       :    id   imi
#> type        : <int> <num>
#> values      :     1   123
#>                   2   0.4
#>                   3   706

0
投票

您的示例数据

library(terra)
long_lat <- data.frame(lon = c(18.5,18.5,18.5,18.6,18.6), 
                       lat = c(-34, -33.9, -33.6,-33.6,-34))
atts <- data.frame(imi = c(123, 0.4, 706,21,9))

以下是使用这些坐标和属性创建 SpatVector 的四种方法

#1 
pts <- vect(as.matrix(long_lat), atts=atts, crs="+proj=longlat")

#2
pts <- vect(cbind(long_lat, atts), crs="+proj=longlat")

#3
pts <- vect(long_lat,  crs="+proj=longlat")
pts <- cbind(pts, atts)

#4
pts <- vect(long_lat,  crs="+proj=longlat")
values(pts) <- atts

#错误 pts_jan <- vect(long_lat, atts = atts, crs="+proj=longlat +datum=WGS84 +no_defs")

© www.soinside.com 2019 - 2024. All rights reserved.