我有一个纬度和经度坐标列表,并希望找出它们所在的国家/地区.
我修改了一个关于lat-long到美国各州的问题的答案,并且有一个工作功能,但我遇到的问题是worldHires地图(来自mapdata包裹)可怕地过时并且包含许多过时的国家,如南斯拉夫和苏联.
如何修改此函数以使用更现代的包,例如rworldmap?到目前为止,我只是挫败了自己...
library(sp)
library(maps)
library(rgeos)
library(maptools)
# The single argument to this function, points, is a data.frame in which:
# - column 1 contains the longitude in degrees
# - column 2 contains the latitude in degrees
coords2country = function(points)
{
# prepare a SpatialPolygons object with one poly per country
countries = map('worldHires', fill=TRUE, col="transparent", plot=FALSE)
names = sapply(strsplit(countries$names, ":"), function(x) x[1])
# clean up polygons that are out of …Run Code Online (Sandbox Code Playgroud) 我有一个带lat/lon坐标的数据框:
head(COORD)
LAT LON
1 69.34 16.17
2 69.20 17.92
3 69.59 17.87
4 69.17 18.52
5 69.42 18.95
6 69.22 18.91
Run Code Online (Sandbox Code Playgroud)
我想检索每个点的国家/地区名称并将其添加为第三列.也许which结合使用map来检索点是哪个多边形,但我无法弄清楚如何.