[R-sig-Geo] rasterize shape file and output as .img
Roger.Bivand at nhh.no
Sat Apr 4 12:26:57 CEST 2009
On Fri, 3 Apr 2009, milton ruser wrote:
> Hi Roger,
> I think I am making something wrong (see the error message, please).
> reser is the polygon object that I read from a shapefile.
> Thanks for your time.
>  "SpatialPolygonsDataFrame"
>  "sp"
>> head(reser at data)
> DOCNAME area_ha ClassCover
> 22 JRN-720 - 271,0m 8022.687 1
>> resolution<-c(60,60) #meters
>> #GridTopology(cellcentre.offset, cellsize, cells.dim)
>> gride<-GridTopology(ccoffset, resolution, cdim)
> Formal class 'GridTopology' [package "sp"] with 3 slots
> ..@ cellcentre.offset: Named num [1:2] 283916 8578881
> .. ..- attr(*, "names")= chr [1:2] "r1" "r2"
> ..@ cellsize : num [1:2] 60 60
> ..@ cells.dim : int [1:2] 313 1280
>> overlay(reser at data$ClassCover, gride)
> Error in function (classes, fdef, mtable) :
> unable to find an inherited method for function "overlay", for signature
> "numeric", "GridTopology"
Try SpatialGrid(gride) instead - look at getMethods(overlay) if it helps
(it may not, there are many methods). Also see the thread on this list (a
RSiteSearch("rasterize") does help.
> On Fri, Apr 3, 2009 at 3:40 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>> On Fri, 3 Apr 2009, milton ruser wrote:
>> Dear all,
>>> I have a set of shapefile and I need rasterized it using a collumn called
>>> and with the resolution of 30 meters. How can I do this on R?
>> Use bbox() of the SpatialPolygonDataFrame to find the extent. Create a
>> GridTopology object, and overlay the polygons - possibly just with
>> ClassCover - and the SpatialGrid built with the GridTopology object. This
>> should yield a SpatialGridDataFrame with a single band, with NAs outside the
>> polygons, and the polygon column values for raster cells where their centres
>> fall inside the polygons.
>> Another thing is that I need to output the raster as IMG (erdas/arcgis)
>> writeGDAL in rgdal.
>> Hope this helps,
>>> Any help are welcome.
>>> Best wishes,
>>> R version 2.9.0 alpha (2009-03-26 r48224)
>>> attached base packages:
>>>  stats graphics grDevices utils datasets methods base
>>> other attached packages:
>>>  rgdal_0.6-7 maptools_0.7-20 sp_0.9-32 foreign_0.8-34
>>> loaded via a namespace (and not attached):
>>>  grid_2.9.0 lattice_0.17-20
>>> [[alternative HTML version deleted]]
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>> Roger Bivand
>> Economic Geography Section, Department of Economics, Norwegian School of
>> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo