创建 SpatiaPointDataframe 时 decimalLongitude 和 decimalLatitude 的问题
Problem with decimalLongitude and decimalLatitude for create a SpatiaPointDataframe
我是 R 的新手,我正在努力学习。
我有一个来自 Gbif 的巨大数据框(900.000 行),其中包含我的物种名称以及 decimalLongitude 和 decimalLatitude 但是当我尝试像往常一样使用 coordinates(data.frame) <- ~ lon + lat
函数创建 SpatialPointDataframe 时(我在列名之前进行了更改来自 lon ecc 中的 decimalLongitude... 我删除了物种的名称,所以在我的分析中,我只有一个“lon,lat 和 species=1”:
这是我的数据框中的 head()
函数
lon lat species
1 4.841.452 5317168 1
2 10.380.893 48888992 1
3 12.999.839 52388378 1
4 1.002.614 53190685 1
5 8.820.133 50520302 1
R 回复:#Error in .local(obj, ...): cannot derive coordinates from non-numeric matrix
所以我看到了数据框,我注意到我的坐标有点奇怪。
你有什么想法吗?我需要转换坐标?
我看了看,但没有找到解决方案。
感谢您花时间回答我。
祝您工作愉快!
您遇到的问题是 lon
列属于 class character
而不是 class numeric
。所以你需要转换这个列。请找到一种可能的解决方案(参见下面的 reprex)。
Reprex
- 您的数据
points <- read.table(text = "lon lat species
1 4.841.452 5317168 1
2 10.380.893 48888992 1
3 12.999.839 52388378 1
4 1.002.614 53190685 1
5 8.820.133 50520302 1", header = TRUE)
- 代码
library(raster)
# Convert 'lon' column into numeric
points$lon <- as.numeric(gsub("\." ,"", points$lon))
# converting to SpatialPointsDataFrame
coordinates(points) <- ~lon+lat
- 输出
points
#> class : SpatialPointsDataFrame
#> features : 5
#> extent : 1002614, 12999839, 5317168, 53190685 (xmin, xmax, ymin, ymax)
#> crs : NA
#> variables : 1
#> names : species
#> min values : 1
#> max values : 1
由 reprex package (v2.0.1)
于 2021-12-10 创建
我是 R 的新手,我正在努力学习。
我有一个来自 Gbif 的巨大数据框(900.000 行),其中包含我的物种名称以及 decimalLongitude 和 decimalLatitude 但是当我尝试像往常一样使用 coordinates(data.frame) <- ~ lon + lat
函数创建 SpatialPointDataframe 时(我在列名之前进行了更改来自 lon ecc 中的 decimalLongitude... 我删除了物种的名称,所以在我的分析中,我只有一个“lon,lat 和 species=1”:
这是我的数据框中的 head()
函数
lon lat species
1 4.841.452 5317168 1
2 10.380.893 48888992 1
3 12.999.839 52388378 1
4 1.002.614 53190685 1
5 8.820.133 50520302 1
R 回复:#Error in .local(obj, ...): cannot derive coordinates from non-numeric matrix
所以我看到了数据框,我注意到我的坐标有点奇怪。
你有什么想法吗?我需要转换坐标?
我看了看,但没有找到解决方案。
感谢您花时间回答我。
祝您工作愉快!
您遇到的问题是 lon
列属于 class character
而不是 class numeric
。所以你需要转换这个列。请找到一种可能的解决方案(参见下面的 reprex)。
Reprex
- 您的数据
points <- read.table(text = "lon lat species
1 4.841.452 5317168 1
2 10.380.893 48888992 1
3 12.999.839 52388378 1
4 1.002.614 53190685 1
5 8.820.133 50520302 1", header = TRUE)
- 代码
library(raster)
# Convert 'lon' column into numeric
points$lon <- as.numeric(gsub("\." ,"", points$lon))
# converting to SpatialPointsDataFrame
coordinates(points) <- ~lon+lat
- 输出
points
#> class : SpatialPointsDataFrame
#> features : 5
#> extent : 1002614, 12999839, 5317168, 53190685 (xmin, xmax, ymin, ymax)
#> crs : NA
#> variables : 1
#> names : species
#> min values : 1
#> max values : 1
由 reprex package (v2.0.1)
于 2021-12-10 创建