【发布时间】:2019-11-12 14:09:53
【问题描述】:
我一直在使用 R 中 raster 包中的 intersect() 函数将空间多边形数据框(HUC-4 分水岭)裁剪到另一个空间多边形数据框(由科罗拉多州、爱达荷州、蒙大拿州组成的区域)的范围内、犹他州和怀俄明州)。
我想保留与我要剪裁到的空间数据框重叠的空间多边形的整个范围。使用intersect() 剪切 HUC-4 流域,使它们不会超出被剪切到的状态范围。
我正在使用的流域数据可以从以下位置下载:ftp://rockyftp.cr.usgs.gov/vdelivery/Datasets/Staged/Hydrography/WBD/National/GDB/ (WBD_National_GDB.zip)。
该地区包括科罗拉多州、犹他州、爱达荷州、怀俄明州和蒙大拿州的数据是从以下可用的县数据中提取的:https://catalog.data.gov/dataset/tiger-line-shapefile-2017-nation-u-s-current-county-and-equivalent-national-shapefile。
我用intersect()函数做剪辑的代码如下:
library(raster)
library(dplyr)
library(spdplyr)
library(rgdal)
library(rgeos)
# albers equal area projection
proj <- CRS("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs ")
counties <- readOGR(dsn = "./data/tl_2017_us_county/tl_2017_us_county.shp")
# filtering out only counties in our 5 states of interest
counties <- counties %>%
filter(STATEFP %in% c("08", "16", "30", "49", "56"))
# transforming to albers projection
counties <- spTransform(counties, proj)
# create a region shapefile (to clip watersheds with)
region <- gUnaryUnion(counties)
# Make Region into a SpatialPolygonsDataFrame
row.names(region) <- as.character(1:length(region))
region_data <- c("West")
region_data <- as.data.frame(region_data)
colnames(region_data) <- "Region"
region <- SpatialPolygonsDataFrame(region, region_data)
file <- "./data/WBD_National_GDB/WBD_National_GDB.gdb"
# huc4 watersheds
huc4 <- readOGR(dsn = file, layer = "WBDHU4")
# transforming to albers projection
huc4 <- spTransform(huc4, proj)
# selecting only huc4 watersheds that intersect with our states of interest
huc4_clip <- raster::intersect(huc4, region)
# plot the result
plot(huc4_clip)
我想要一个输出文件,它不会裁剪位于感兴趣区域边缘的空间多边形的范围,但不包含任何不直接与感兴趣区域重叠的空间多边形。是否有任何其他我可以使用的函数类似于intersect(),但不会裁剪区域边界上空间多边形的范围?
【问题讨论】:
-
答案是肯定的,但除非您提供一个最小(尽可能简单)可重现的示例,否则我们无法帮助您。或许请参阅
?raster::intersect以获得灵感。
标签: r geospatial spatial r-raster