大型数据集中每个邮政编码的最近气象站?

时间:2017-11-10 02:30:01

标签: r nearest-neighbor noaa

我正在寻找一种有效的方法将大型数据集中的每条记录链接到最近的NOAA气象站。数据集包含9位邮政编码,NOAA气象站有长期信息。有人提供最好的方法吗?谢谢!

编辑:使用代码进行更新,以防万一其他人希望找到最近的NOAA气象站到一组邮政编码/如果有更好的方法可以做到这一点的建议。

基于此问题中提供的代码:Finding nearest neighbour (log, lat), then the next closest neighbor, and so on for all points between two datasets in R

temp_stations从https://www1.ncdc.noaa.gov/pub/data/normals/1981-2010/station-inventories/temp-inventory.txt下载(用于开发温度数据集的气象站)

zipcodes是一个包,其中包含美国每个邮政编码的纬度为long的数据集。

install.packages("zipcode")
require(zipcode)
data(zipcode)
#prime.zips is a subset of "zipcode" created by selecting just the zip codes contained in my original dataset. running the code below on the whole zipcode dataset crashed R on my computer.
install.packages("geosphere")
require(geosphere)
mat <- distm(prime.zips[ ,c('longitude','latitude')], temp_stations[ ,c(3,2)], fun=distGeo)
# assign the weather station id to each record in prime.zips based on shortest distance in the matrix
prime.zips$nearest.station <- temp_stations$station.id[apply(mat, 1, which.min)]

0 个答案:

没有答案