我正在尝试为各种地理区域(即县/邮政编码)映射多边形。根据我在这个博客上的发现,我可以很容易地为县完成这项工作。
library(rgdal)
library(rgeos)
library(leaflet)
url<-"http://www2.census.gov/geo/tiger/TIGER2010DP1/County_2010Census_DP1.zip"
downloaddir<-getwd()
destname<-"tiger_county.zip"
download.file(url, destname)
unzip(destname, exdir=downloaddir, junkpaths=TRUE)
filename<-list.files(downloaddir, pattern=".shp", full.names=FALSE)
filename<-gsub(".shp", "", filename)
# ----- Read in shapefile (NAD83 coordinate system)
# ----- this is a fairly big shapefile and takes 1 minute to read
dat<-readOGR(downloaddir, "County_2010Census_DP1")
# ----- Create a subset of New York counties
subdat<-dat[substring(dat$GEOID10, 1, 2) == "36",]
# ----- Transform to EPSG 4326 - WGS84 (required)
subdat<-spTransform(subdat, CRS("+init=epsg:4326"))
# ----- save the data slot
subdat_data<-subdat@data[,c("GEOID10", "ALAND10")]
# ----- simplification yields a SpatialPolygons class
subdat<-gSimplify(subdat,tol=0.01, topologyPreserve=TRUE)
# ----- to write to geojson we need a SpatialPolygonsDataFrame
subdat<-SpatialPolygonsDataFrame(subdat, data=subdat_data)
leaflet() %>%
addTiles() %>%
addPolygons(data=subdat)
但是,如果我使用不同的邮政编码文件运行完全相同的代码
url <- "http://www2.census.gov/geo/tiger/GENZ2014/shp/cb_2014_us_zcta510_500k.zip"
我得到了一个完全不同的国家地区,而不是纽约。
不确定是否有人更熟悉这些数据集和这些函数来解释为什么会发生这种差异?