【问题标题】:County average from latitude and longitude经纬度县平均值
【发布时间】:2019-04-18 17:02:10
【问题描述】:

我有一个大数据框(832k 行),其纬度和经度采用网格格式加上一个变量。我想绘制每个县这个变量的平均值。问题是我没有逐点识别县或州,只有坐标。

抱歉,我不确定如何包含可复制的示例

【问题讨论】:

  • dput(head(your_data)) 是分享可重现示例的好方法。或者,如果您有因素,dput(droplevels(head(your_data)))
  • 您可以使用rworldmap 包根据纬度/经度提取国家/地区名称,然后使用dplyr::group_bysummarise 作为该变量的平均值
  • 此外,谷歌搜索 get county from lat long 有很多有用的链接,包括来自 SO like this one 和 GIS stack exhcange like this one 的很多 Q/A。仅限于 R 标签,this looks helpful。你试过这些吗?

标签: r maps gis


【解决方案1】:

两种方法:

1) 计算所有纬度/经度网格的平均值。这种方法使您的县中心向更高密度的网格倾斜

2) 计算网格的边界[min-max lat/lon] 并平均边界。这种方法将县中心准确地置于网格跨度的中心。

【讨论】:

    【解决方案2】:

    您将需要获取县(或州)数据,然后将其与您的数据框进行空间连接。此类数据的一个可能来源是美国人口普查局发布的 TIGER shapefile(参见例如https://catalog.data.gov/dataset/tiger-line-shapefile-2016-nation-u-s-current-county-and-equivalent-national-shapefile)。

    然后您可以使用sf 包将 shapefile 读入 R,将其与您的数据连接起来,然后使用常规汇总函数按县汇总您的数据。

    library(sf)
    
    filename <- 'https://www2.census.gov/geo/tiger/TIGER2016/COUNTY/tl_2016_us_county.zip'
    tmpfile <- tempfile()
    tmpdir <- tempdir()
    download.file(filename,tmpfile)
    unzip(zipfile = tmpfile, exdir = tmpdir)
    county_data <- st_read(paste0(tmpdir, '/tl_2016_us_county.shp'))
    unlink(tmpfile)
    unlink(tmpdir)
    

    【讨论】:

      猜你喜欢
      • 2011-08-17
      • 1970-01-01
      • 2017-02-06
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      相关资源
      最近更新 更多