【问题标题】:Layer won't rasterize using raster package in r图层不会在 r 中使用栅格包进行栅格化
【发布时间】:2013-06-25 15:18:50
【问题描述】:

我在使用 R 中的 raster 包对 shapefile 进行光栅化时遇到问题。

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")

返回如下错误:

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

谁能看到我在这里错过/搞砸了什么?

谢谢

【问题讨论】:

  • 这是一个数据问题,因为我能够使用另一个 shapefile 运行。但是,shapefile 显示正确,并且属性表在 Arcmap 中看起来不错。问题也是posted on GISStackExchange

标签: r raster rasterize


【解决方案1】:

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

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

【讨论】:

  • 谢谢。当修复如此简单时非常好。
猜你喜欢
  • 1970-01-01
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-14
相关资源
最近更新 更多