My appologies. The previous script had few (5) typos: > library(rgdal) > library(RSAGA) # load the gridded map: > rastermap <- readGDAL("rastermap.asc") > rsaga.esri.to.sgrd(in.grids=" rastermap.asc", out.sgrds=" rastermap.sgrd", > in.path=getwd()) # convert the polygon map to a raster map: > cellsize <- raster...@grid@cellsize[1] > rsaga.get.usage(lib="grid_gridding", module=3) > rsaga.geoprocessor(lib="grid_gridding", module=3, > param=list(GRID="polygons.sgrd", INPUT="polygons.shp", FIELD=1, LINE_TYPE=0, USER_CELL_SIZE=cellsize, user_x_extent_min=raster...@bbox[1,1]+cellsize, user_x_extent_max=raster...@bbox[1,2]-cellsize, user_y_extent_min=raster...@bbox[2,1]+cellsize, user_y_extent_max=raster...@bbox[2,2]-cellsize)) > rsaga.sgrd.to.esri(in.sgrds="polygons.sgrd", out.grids="polygons.asc", > out.path=getwd(), prec=0) > rastermap$polygons <- as.factor(readGDAL("polygons.asc")$band1) # summary statistics per polygon class: > raster.polygons <- boxplot(band1 ~ polygons, raster...@data, > col=rainbow(length(levels(rastermap $polygons)))) > str(raster.polygons)
HTH Tom Hengl http://spatial-analyst.net > -----Original Message----- > From: r-sig-geo-boun...@stat.math.ethz.ch > [mailto:r-sig-geo-boun...@stat.math.ethz.ch] On Behalf > Of Tomislav Hengl > Sent: Wednesday, January 28, 2009 9:56 AM > To: r-sig-geo@stat.math.ethz.ch > Cc: alexander.h...@csiro.au > Subject: Re: [R-sig-Geo] calculate raster values based on vector regions > > > Dear Herry, > > If I understand what you problem, one solution is to use R+SAGA. You should > first convert the > polygon map to the same grid, and then you can load it to R and do any type > of aggregation: > > > library(maptools) > > library(rgdal) > > library(RSAGA) > # load the gridded map: > > rastermap <- readGDAL("rastermap.asc") > # load the shapefile: > > rsaga.esri.to.sgrd(in.grids=" rastermap.asc", out.sgrds=" rastermap.sgrd", > > in.path=getwd()) > # convert the polygon map to a raster map: > > cellsize <- raster...@grid@cellsize[1] > > rsaga.geoprocessor(lib="grid_gridding", module=3, > > param=list(GRID="polygons.sgrd", > INPUT="polygons.shp", FIELD=1, LINE_TYPE=0, USER_CELL_SIZE=cellsize, > user_x_extent_min=raster...@bbox[1,1]+cellsize, > user_x_extent_max=raster...@bbox[1,2]-cellsize, > user_y_extent_min=raster...@bbox[2,1]+cellsize, > user_y_extent_max=raster...@bbox[2,2]-cellsize)) > > rsaga.sgrd.to.esri(in.sgrds="polygons.sgrd", out.grids="polygons.asc", > > out.path=getwd(), prec=0) > > rastermap$polygons <- as.factor(readGDAL("polygons.asc")) > # summary statistics per polygon class: > > raster.polygons <- boxplot(band1 ~ polygons, rastermap @data, > col=rainbow(length(levels(negotingrid$SOIL)))) > > str(raster.polygons) > > You will of course need to adjust the "FIELD" position in the attribute table > and the precision > "prec". > > To obtain and use SAGA, check this article: > http://spatial-analyst.net/wiki/index.php?title=Software > > cheers, > > How is the weather now in Canberra? In Amsterdam is freezing brrr. > > T. Hengl > > > > -----Original Message----- > > From: r-sig-geo-boun...@stat.math.ethz.ch > > [mailto:r-sig-geo-boun...@stat.math.ethz.ch] On Behalf > > Of alexander.h...@csiro.au > > Sent: Wednesday, January 28, 2009 2:10 AM > > To: r-sig-geo@stat.math.ethz.ch > > Subject: [R-sig-Geo] calculate raster values based on vector regions > > > > > > Hi List, > > > > How would I go about assigning values to a raster based on polygon regions > > in R. Examples would > be > > most appreciated. > > > > I have (vector) regions assigned to a specific value. The raster has NAs > > and some pixels where > > these values are likely to occur on ground. I need to assign these values > > to the raster and can > do > > this in ArcInfo through vectors and rasterizing but only to a limited > > raster size. And R is much > > more preferable anyway... > > > > Any help appreciated. > > Cheers > > Herry > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo