相关疑难解决方法(0)

R转换zipcode或lat/long到县

我有一个位置列表,其中包含每个位置的城市,州,邮政编码,纬度和经度.

我单独列出了县级经济指标.我玩过zipcode包,ggmap包和其他几个免费地理编码网站,包括美国Gazeteer文件,但似乎无法找到匹配这两个部分的方法.

目前是否有任何包或其他来源这样做?

geocoding r geolocation

23
推荐指数
3
解决办法
2万
查看次数

将纬度和经度坐标转换为R中的国家/地区名称

我有一个纬度和经度坐标列表,并希望找出它们所在的国家/地区.

我修改了一个关于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)

maps r geocode rworldmap

20
推荐指数
2
解决办法
1万
查看次数

R中的反向地理编码循环

我试图反转地理编码一个大型数据集(大约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)

r reverse-geocoding ggmap

10
推荐指数
1
解决办法
5496
查看次数

如何在R中的空间多边形中添加Hawaii和Alaska?

如何将夏威夷和阿拉斯加添加到以下代码(摘自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)

gis maps r r-maptools r-sp

5
推荐指数
1
解决办法
2791
查看次数

从R中的经度和纬度点获取国家(和大陆)

作为我昨天发布的一个问题的后续跟进,是否有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)

我想输出上面添加了国家和大陆列的数据框.作为一个额外的奖励,一个美国州的专栏是美国的(和其他"美国以外的国家)?

maps r

1
推荐指数
1
解决办法
5892
查看次数