我有这个数据帧:
structure(list(Nazwa = c("a", "b"), Miejscowosc = c("aaa", "bbb"
), KodPocztowy = c("09-520", "44-207"), Zainstalowano = c("2020-03-20 00:00:00.000",
"2019-02-27 00:00:00.000"), Szczytowa = c(9.14, 4.5), Latitude = c("52.550000",
"50.101860"), Longitude = c("19.700000", "18.546640")), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
我从aaa.xlsx中读取这些数据文件。
points <- read_xlsx(paste0("From/",qwerty,"/aaa.xlsx"))
然后我尝试使用代码:
points_sp <- SpatialPoints(points[,c(6,7)], CRS("+init=EPSG:4326"))
不幸的是,我得到一个错误:不能从非数字矩阵推导坐标如何解决?
您只需要将字符串转换为数字,并将tbl_df
转换为矩阵或普通数据帧:
points$Latitude <- as.numeric(points$Latitude)
points$Longitude <- as.numeric(points$Longitude)
points_sp <- SpatialPoints(as.data.frame(points[,c(6,7)]), CRS("+init=EPSG:4326"))
points_sp
SpatialPoints:
# Latitude Longitude
# [1,] 52.55000 19.70000
# [2,] 50.10186 18.54664
# Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 +no_defs