R中的栅格包不会光栅化shapefile

时间:2014-03-25 18:31:03

标签: r raster r-raster

我无法使用R中的光栅包光栅化shapefile。我按照上一篇文章中的代码和提示(“2013年6月30日在R中使用光栅包格式化光栅)。但是,我仍然得到了同样的错误“试图获得插槽”coords“来自基本类的对象(”NULL“)没有插槽”。这是一个与上一篇文章不同的问题吗?非常感谢!

shp<-shapefile(NA_CEC_Eco_Level1.shp")
lcRas <- raster(shp);
r <- lcRas

shp          
class       : SpatialPolygonsDataFrame 
features    : 2140 
extent      : -4334052, 3324076, -3313739, 4267265  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs 
variables   : 5
names       : NA_L1CODE,         NA_L1NAME,        NA_L1KEY,   Shape_Leng,   
Shape_Area 
min values  :         0, ARCTIC CORDILLERA,        0  WATER, 1.000517e+04, 1.000668e+07 
max values  :         9,             WATER, 9  GREAT PLAINS, 9.997592e+03, 9.967503e+04 

> r
# class       : RasterLayer 
# dimensions  : 1, 1, 1  (nrow, ncol, ncell)
# resolution  : 7658128, 7581004  (x, y)
# extent      : -4334052, 3324076, -3313739, 4267265  (xmin, xmax, ymin, ymax)
# coord. ref. : NA 

zoneRas <- rasterize(shp, r, "NA_L1CODE")
# Found 2140 region(s) and 2334 polygon(s)
# Error in cbind(poly, rbind(poly[-1, ], poly[1, ])) : 
#   trying to get slot "coords" from an object of a basic class ("NULL") with no slots

zoneRas <- rasterize(shp, r, shp$NA_L1CODE)
# Found 2140 region(s) and 2334 polygon(s)
# Error in cbind(poly, rbind(poly[-1, ], poly[1, ])) : 
#   trying to get slot "coords" from an object of a basic class ("NULL")    with no slots

coordinates(r)
#         x        y
#    [1,] -504987.6 476762.6

coordinates(shp)
#          [,1]          [,2]
# 0     -322524.6431 -2726795.8939
# 1     1195909.0021   142037.0767   
# 2     2126454.5663  1985314.0739
# 3     2052912.8197  2013519.6523
# [etc, etc]

0 个答案:

没有答案