R:地理编码返回的结果多于我的查询
R: geocode is returning more results than my query
我有一个包含近 10k 个位置的数据框,我想获得地理编码能为我找到的尽可能多的坐标,但我的代码没有返回我预期的结果。我会解释。
我有这个:
# Getting records for Promenaea genus for an exemple
library(dismo)
promena<-gbif("Promenaea")
#Once I get all records I keep only those that don't have coordinates
promena<-promena[(is.na(promena$lon)),]
#And then, try to get coordinates for them
b <- try( geocode(promena$cloc) )
我的计划是将我的 Promenaea 物种的数据框与地理编码的结果进行绑定,然后删除那些地理编码无法找到坐标的行(那会有 NA)。但是我的数据框有 259 行和地理编码 returns 318 行结果......所以有些东西不匹配。
我很感激任何提示
所以我一直在研究并找到了一些选择:
dismo::geocode 函数有一个名为 oneRecord 的参数用于此目的:
b <- try( geocode(promena$cloc, oneRecord=TRUE))
但是:
oneRecord
Logical. If TRUE a single record for each item in x is returned. If the API returned multiple records, the values of this record are computed by averaging the coordinates and taking the union of all bounding boxes (says the documentation)
因为我更喜欢真实的测量而不是平均值,所以我一直在寻找,发现 ggmap 也有一个地理编码功能:
#Nem attempt of getting coordinates.
b <- try( ggmap::geocode(promena$cloc))
但我只有坐标,我希望位置与坐标相关联,这样我就可以检查地理编码 return 是否有好的结果,所以我使用了这个参数:
b <- try(ggmap::geocode(promena$cloc, output="more"))
最后,我比较了两种方法的结果,它们几乎相同,所以我想检查记录真的很重要,因为函数确实可能 return 平均值
我有一个包含近 10k 个位置的数据框,我想获得地理编码能为我找到的尽可能多的坐标,但我的代码没有返回我预期的结果。我会解释。 我有这个:
# Getting records for Promenaea genus for an exemple
library(dismo)
promena<-gbif("Promenaea")
#Once I get all records I keep only those that don't have coordinates
promena<-promena[(is.na(promena$lon)),]
#And then, try to get coordinates for them
b <- try( geocode(promena$cloc) )
我的计划是将我的 Promenaea 物种的数据框与地理编码的结果进行绑定,然后删除那些地理编码无法找到坐标的行(那会有 NA)。但是我的数据框有 259 行和地理编码 returns 318 行结果......所以有些东西不匹配。
我很感激任何提示
所以我一直在研究并找到了一些选择:
dismo::geocode 函数有一个名为 oneRecord 的参数用于此目的:
b <- try( geocode(promena$cloc, oneRecord=TRUE))
但是:
oneRecord Logical. If TRUE a single record for each item in x is returned. If the API returned multiple records, the values of this record are computed by averaging the coordinates and taking the union of all bounding boxes (says the documentation)
因为我更喜欢真实的测量而不是平均值,所以我一直在寻找,发现 ggmap 也有一个地理编码功能:
#Nem attempt of getting coordinates.
b <- try( ggmap::geocode(promena$cloc))
但我只有坐标,我希望位置与坐标相关联,这样我就可以检查地理编码 return 是否有好的结果,所以我使用了这个参数:
b <- try(ggmap::geocode(promena$cloc, output="more"))
最后,我比较了两种方法的结果,它们几乎相同,所以我想检查记录真的很重要,因为函数确实可能 return 平均值