我有一个位置列表,其中包含每个位置的城市,州,邮政编码,纬度和经度.
我单独列出了县级经济指标.我玩过zipcode包,ggmap包和其他几个免费地理编码网站,包括美国Gazeteer文件,但似乎无法找到匹配这两个部分的方法.
目前是否有任何包或其他来源这样做?
我有一个纬度和经度坐标列表,并希望找出它们所在的国家/地区.
我修改了一个关于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) 我试图反转地理编码一个大型数据集(大约100k).我使用revgeocode了包中的功能ggmap.我得到了一个条目的结果
48 Grand View Terrace, San Francisco,
CA 94114, USA
48 Grand View Terrace Eureka Valley San Francisco
San Francisco County California United States
postal_code postal_code_suffix
Run Code Online (Sandbox Code Playgroud)
,但我需要自动化该过程并将其用于整个数据集.
我试过了
r <- lapply(revgeocode(location = (c(z$lon),c(z$lat)),
output = "more",
messaging = FALSE, sensor = FALSE, override_limit = FALSE,
client = "", signature = ""))
Run Code Online (Sandbox Code Playgroud)
并在每一步中得到意外','的错误.
我也尝试编写以下循环
r <- for(i in 1:10){
revgeocode(location = ("z$lon", "z$lat"),output = "more", messaging = FALSE, sensor = FALSE, override_limit = FALSE,client = "", signature …Run Code Online (Sandbox Code Playgroud) 如何将夏威夷和阿拉斯加添加到以下代码(摘自Josh O'Brien在这里的答案:R中的国家代码的纬度经度坐标)?
library(sp)
library(maps)
library(maptools)
# The single argument to this function, pointsDF, is a data.frame in which:
# - column 1 contains the longitude in degrees (negative in the US)
# - column 2 contains the latitude in degrees
latlong2state <- function(pointsDF) {
# Prepare SpatialPolygons object with one SpatialPolygon
# per state (plus DC, minus HI & AK)
states <- map('state', fill=TRUE, col="transparent", plot=FALSE)
IDs <- sapply(strsplit(states$names, ":"), function(x) x[1])
states_sp <- map2SpatialPolygons(states, IDs=IDs,
proj4string=CRS("+proj=longlat +datum=wgs84")) …Run Code Online (Sandbox Code Playgroud) 作为我昨天发布的一个问题的后续跟进,是否有R中的包/函数可以给我一个由经度和纬度定义的点所在的国家(和大陆)?在MatLab中所做的事情.
Dataframe看起来像这样......
Point_Name Longitude Latitude
University of Arkansas 36.067832 -94.173655
Lehigh University 40.601458 -75.360063
Harvard University 42.379393 -71.115897
Run Code Online (Sandbox Code Playgroud)
我想输出上面添加了国家和大陆列的数据框.作为一个额外的奖励,一个美国州的专栏是美国的(和其他"美国以外的国家)?
r ×5
maps ×3
geocode ×1
geocoding ×1
geolocation ×1
ggmap ×1
gis ×1
r-maptools ×1
r-sp ×1
rworldmap ×1