纬度/经度的邮政编码(批量查询) [英] Zip Codes from Lat/Lon (batch query)

查看:80
本文介绍了纬度/经度的邮政编码(批量查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带1500个纬度/经度条目的data.frame.我需要将这些坐标映射到他们的邮政编码.除了一次将它们一次输入到geonames -type api之外,还有其他方法吗?我想要一个 R 中的软件包,该软件包采用lat-lon组合,并为data.frame的每一行生成一个邮政编码.

I have a data.frame with 1500 latitude/longitude entries. I need to map these coordinates to their zip codes. Is there a way to do this besides entering them in one at a time to a geonames -type api? I would like a package in R that takes in a lat-lon combo and produces a zip code for every row of my data.frame.

推荐答案

使用Open Streetmap API,您可以尝试

Using the Open Streetmap API, you could try

library(RCurl)
library(RJSONIO)

latlon2zip <- function(lat, lon) {
    url <- sprintf("http://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1", lat, lon)
    res <- fromJSON(url)
    return(res[["address"]][["postcode"]])
}

latlon2zip(lat=52.5487429714954, lon=-1.81602098644987)

为了在 transform 中使用 latlon2zip 函数,请使用 Vectorize .

In order to use the latlon2zip function in transform, use Vectorize.

这篇关于纬度/经度的邮政编码(批量查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆