我正在尝试从数据集中创建一列国家/地区名称,该数据集有一列用于纬度,一列用于经度。但是,当我使用函数
bdc_country_from_coordinates()
时,我收到此错误消息:
wk_handle.wk_wkb(wkb,s2_geography_writer(定向=定向,:
)中的错误 循环 0 无效:边 1028 与边 1033 具有重复的顶点
有谁知道如何解决这个问题吗?下面附上我的代码:
library(bdc)
library(rnaturalearthdata)
library(rnaturalearth)
# latlong_data is my dataset with a column for lat and a column for long
# called "decimalLatitude" and "decimalLongitude"
bdc_country_from_coordinates(latlong_data,
lat = "decimalLatitude",
lon = "decimalLongitude",
country = "country”)
我还在此页面上运行了示例并收到了相同的错误消息。
在地球类型几何体上运行某些空间函数时会出现此错误,例如一个 S2 对象。为了解决这个问题,您可以指示 R 在运行函数时不要使用 S2。
我不确定您是否需要在运行此代码之前安装
sf
软件包,但如果您正在进行空间分析,无论如何它都值得拥有。
install.packages("sf")
library(bdc)
# Sample point coordinates dataframe based on your description
latlong_data <- data.frame(decimalLatitude = c(-23.3409011, 20.493914, 47.1692336),
decimalLongitude = c(133.0168861, 78.8001911, 3.3106851))
# Turn off spherical geometry
sf::sf_use_s2(FALSE)
# Spherical geometry (s2) switched off
# Run your code
bdc_country_from_coordinates(latlong_data,
lat = "decimalLatitude",
lon = "decimalLongitude",
country = "country")
# A tibble: 3 × 3
decimalLatitude decimalLongitude country
<dbl> <dbl> <chr>
1 -23.3 133. Australia
2 20.5 78.8 India
3 47.2 3.31 France
# Turn spherical geometry on (I like to include this in case I need it in subsequent steps)
sf::sf_use_s2(TRUE)
# Spherical geometry (s2) switched on