【问题标题】:making a choropleth in R: merging zip code shapefiles from multiple states在 R 中制作 choropleth:合并来自多个州的邮政编码 shapefile
【发布时间】:2011-07-09 06:10:44
【问题描述】:

受到Developing Geographic Thematic Maps with R 此处帖子的启发,我正在考虑构建基于邮政编码的等值线地图。我已经从http://www.census.gov/geo/www/cob/z52000.html 下载了新罕布什尔州和缅因州的形状文件,但我对合并或合并这两个州的 .shp 文件感兴趣。

maptools 包中是否有一种机制可以在您使用readShapeSpatial() 读取两个 .shp 文件后进行这种合并或连接?也欢迎输入,例如使用RgoogleMaps 包会更容易。

【问题讨论】:

  • 此链接 (r-sig-geo.2731867.n2.nabble.com/…) 正在合并。 nabble 档案应该是处理空间数据的金矿。
  • 嗯...不知道 R-sig-geo 已经进入了 Nabble。不幸的是,它没有与其他 R 论坛分组。
  • 我用了将近五年的 GIS 才意识到这一点,但是……它是“choropleth”而不是“chloropleth”
  • @J.温彻斯特,好点...我刚刚将标题更正为“choropleth”。

标签: r shapefile


【解决方案1】:

GeoMerge 是一个用于合并 Shapefile 的免费工具。合并 SHP 和 DBF 部件。似乎工作正常,但我没有推太多。

【讨论】:

  • 链接已损坏。但在 CRAN 上有一个包 geomerge
【解决方案2】:

我跟进了 Roman Luštrik 发布的链接,下面的回答是对http://r-sig-geo.2731867.n2.nabble.com/suggestion-to-MERGE-or-UNION-3-shapefiles-td5914413.html#a5916751 的轻微修改。

以下代码将允许您合并从Census 2000 5-Digit ZIP Code Tabulation Areas (ZCTAs) Cartographic Boundary Files 获得的.shp 文件并绘制它们。

在这种情况下,我下载了马萨诸塞州、新罕布什尔州和缅因州的 .shp 文件和关联的 .dbf.shx 文件。

library('maptools')
library('rgdal')

setwd('c:/location.of.shp.files')

# this location has the shapefiles for zt23_d00 (Maine), zt25_d00 (Mass.), and zt33_d00 (New Hampshire).

# columns.to.keep
# allows the subsequent spRbind to work properly

columns.to.keep <- c('AREA', 'PERIMETER', 'ZCTA', 'NAME', 'LSAD', 'LSAD_TRANS')

files <- list.files(pattern="*.shp$", recursive=TRUE, full.names=TRUE) 

uid <-1 

# get polygons from first file

poly.data<- readOGR(files[1], gsub("^.*/(.*).shp$", "\\1", files[1])) 
n <- length(slot(poly.data, "polygons"))
poly.data <- spChFIDs(poly.data, as.character(uid:(uid+n-1))) 
uid <- uid + n 
poly.data <- poly.data[columns.to.keep]

# combine remaining polygons with first polygon

for (i in 2:length(files)) {
    temp.data <- readOGR(files[i], gsub("^.*/(.*).shp$", "\\1",files[i]))
    n <- length(slot(temp.data, "polygons")) 
    temp.data <- spChFIDs(temp.data, as.character(uid:(uid+n-1))) 
    temp.data <- temp.data[columns.to.keep]
    uid <- uid + n 
    poly.data <- spRbind(poly.data,temp.data) 
}

plot(poly.data)

# save new shapefile

combined.shp <- 'combined.shp'
writeOGR(poly.data, dsn=combined.shp, layer='combined1', driver='ESRI Shapefile') 

【讨论】:

    猜你喜欢
    • 2016-05-16
    • 2023-04-06
    • 1970-01-01
    • 2021-04-13
    • 2018-11-23
    • 1970-01-01
    • 2013-04-05
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多