问问题
224 次
1 回答
0
这里有一些注意事项
readOGR
不适用于您提供的参数。该shapefile
功能将。我更改了变量名,因为在将数据读入 R 后,它们不再是 shapefile。大概是SpatialPolygonsDataFrame
对象
library(raster)
p_ELC <- shapefile("EconomicLandConsesions/ELC.shp")
p_CF <- shapefile("Communityforestry/Community_forestryPolygon.shp")
p_NPA <- shapefile("Natural-Protected-Areas/Natural Protected Areas.shp")
p_Ecoregion <- shapefile("TerrestrialEcoRegionsWWF/KH_TerrEcoregions_Dslv.shp")
# you can create a list right away, but with only a few objects that might make things harder for you
# f <- c("EconomicLandConsesions/ELC.shp", "Communityforestry/Community_forestryPolygon.shp", "Natural-Protected-Areas/Natural Protected Areas.shp", "TerrestrialEcoRegionsWWF/KH_TerrEcoregions_Dslv.shp")
# pList <- lapply(f, shapefile)
显然,一些多边形具有 UTM CRS,而另一些则没有。确保它们都转换为相同的 CRS。
utmcrs <- crs(p_CF)
p_Ecoregion <- spTransform(p_Ecoregion, utmcrs)
# create Raster template
r <- raster(resolution=30, ext = extent(p_Ecoregion), crs = utmcrs)
# make a list of the SpatialPolygonDataFrame objects
listP <- list(p_ELC, p_CF, p_NPA, p_Ecoregion)
我不知道现在该怎么办。在您的示例中,您覆盖了输出三次。我假设你想要四个栅格
x <- list()
for(i in 1:length(listP)){
x[[i]] <- rasterize(listP[[i]]), r)
}
s <- stack(x)
plot(s)
于 2018-02-17T23:29:32.437 回答