我正在尝试加入两个类似 shapefile 的子集,一个来自美国的州,第二个来自加拿大的省份。数据集可在此处获得:来自 Geocommons 的 shapefile
我注意到在这两个文件中,属性略有不同。在美国地图中,州被标记为“STATE_NAME”,但在加拿大地图中,属性只是“NAME”。这是一个问题,因为我无法将两个 shapefile 合并为一个。有没有人可以解决这个问题?
到目前为止,这是我的代码:
require (raster)
#load in boundaries for plotting
state <- readOGR(dsn = '/usa_state_shapefile.shp', layer = "usa_state_shapefile")
projection(state) <- CRS("+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs")
# Subset US shapefile by desired states
nestates <- c("Maine", "Vermont", "Massachusetts", "New Hampshire" ,"Connecticut",
"Rhode Island","New York","Pennsylvania", "New Jersey",
"Maryland", "Delaware", "Virginia", "West Virginia", "North Carolina")
state.sub <- state[as.character(state@data$STATE_NAME) %in% nestates, ]
summary(state.sub)
provinces<-readOGR (dsn = '/canadian_provinces.shp', layer = "canadian_provinces")
projection(provinces) <- CRS("+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs")
canprov<- c ("Quebec", "Ontario", "Newfoundland & Labrador", "New Brunswick", "Prince Edward Island", "Nova Scotia")
provinces.sub <- provinces[as.character(provinces@data$NAME) %in% canprov,]
summary (provinces.sub)
我猜如果我将属性重命名为“NAME”之类的相同名称,那么我应该能够使用某种rbind
或cbind
函数合并两个 shapefile。