栅格不裁剪到 shapefile

Raster not cropping to shapefile

我正在尝试合并 shapefile 中的一些状态,并生成我可以使用 downstreamraster。我已经合并了状态,但是当我创建一个空栅格以使用裁剪功能进行栅格化时似乎失败了。我是 R 中的 GIS features 的新手,非常感谢您的帮助。 Shapefile is fromhttp://www.arcgis.com/home/item.html?id=f7f805eb65eb4ab787a0a3e1116ca7e5

library(maptools)
library(shapefiles)
library(raster)
usa.states <- readOGR(dsn = "states_21basic/", layer = "states")
head(usa.states)
Co=usa.states[usa.states@data$STATE_NAME== "Colorado",]
Nm=usa.states[usa.states@data$STATE_NAME== "New Mexico",]
Az=usa.states[usa.states@data$STATE_NAME== "Arizona",]
Ut=usa.states[usa.states@data$STATE_NAME== "Utah",]
Corners= spRbind(spRbind(spRbind(Co,Ut),Nm),Az)
CRS="+proj=longlat +datum=WGS84"
Corners=spTransform(Corners, CRS(CRS))
> extent(Corners)
class       : Extent 
xmin        : -114.8218 
xmax        : -102.0372 
ymin        : 31.33563 
ymax        : 42.0023 
cor.ext=extent(Corners)
r<-raster(ncol=ncol(Corners), nrow=nrow(Corners), crs=CRS)
Corners.crop= crop(r,cor.ext, snap="out")

当我调用 'Corners.crop' 的范围时,我收到:

> extent(Corners.crop)
class       : Extent 
xmin        : -180 
xmax        : -36 
ymin        : 0 
ymax        : 45 

我很困惑我缺少什么来让它工作。 我也希望有一个 1Km 的分辨率,并且很好奇在空栅格上或在我栅格化形状之后更改分辨率是否会更好。

library(rgdal)
library(raster)
library(rgeos)

usa.states <- readOGR("states.shp", layer = "states")

# Here we subset once
Corners <- usa.states[usa.states$STATE_NAME %in% c("Colorado", "New Mexico","Arizona","Utah"),]

# Dissolve polygons into one
Corners <- gUnaryUnion(Corners)

# Create a 20x20 raster using the extent of Corners
# The number of rows and columns can be change to increase/reduce the resolution
r <- raster(extent(Corners), ncol=20, nrow=20, crs=CRS(proj4string(Corners)))

# Rasterize
Corners.crop <- rasterize(Corners, r)