2013-06-25 63 views
1

我无法使用栅格包河返回层不会栅格化中的R

shp<-shapefile(ZoneShape); 
lcRas<-raster(lcRaster); 

r<-raster(ncol=ncol(lcRas), nrow=nrow(lcRas), crs=CRS); 
res(r)<-res(lcRas); 
extent(r)<-extent(lcRas); 

>r 

class  : RasterLayer 
dimensions : 22610, 27959, 632152990 (nrow, ncol, ncell) 
resolution : 1, 1 (x, y) 
extent  : 554739, 582698, 3837197, 3859807 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +towgs84=0,0,0 

shp$GID<-1:nrow(shp); 

> shp 

class  : SpatialPolygonsDataFrame 
nfeatures : 1 
extent  : 554838, 582597.6, 3837297, 3859707 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=15 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 
nvariables : 14 
names  : SP_ID,    NAME, Shape_Leng, Shape_Area, GID 

>zoneRas<-rasterize(shp, r, "GID") 

以下错误光栅化shape文件使用光栅包:

trying to get slot "coords" from an object of a basic class ("NULL") with no slots. 

任何人都可以看看我在想什么/搞砸了吗?

感谢

+0

这是一个数据问题,因为我能够与另一个shapefile一起运行。但是,shapefile显示正确,并且Arcmap中的属性表看起来不错。问题也在[贴在GISStackExchange上](http://gis.stackexchange.com/questions/64343/r-raster-package-rasterize-failingno-slots)。 – RichT

回答

2

这是一个发生在当SpatialPolygonsDataFrame对象只有一个几何的错误。这是一个解决方法:

zoneRas <- rasterize(shp, r, shp$GID) 
+0

谢谢。非常好,当一个修复很容易。 – RichT