[R-sig-Geo] Polygon to raster?

Tomislav Hengl hengl at spatial-analyst.net
Mon Aug 3 09:42:58 CEST 2009


SAGA has a module to convert from shapes to grids (GRASS can do the same).

See:

> library(RSAGA)
> rsaga.get.usage(lib="grid_gridding", module=0)
SAGA CMD 2.0.3
library path:   C:/Progra~1/saga_vc/modules
library name:   grid_gridding
module name :   Shapes to Grid
Usage: 0 [-GRID <str>] -INPUT <str> [-FIELD <num>] [-TARGET_TYPE <num>] [-LINE_TYPE <num>]
[-USER_CELL_SIZE <str>] [-USER_FIT_EXTENT] [-USER_X_EXTENT_MIN <str>] [-USER_X_EXTENT_MAX <str>]
[-USER_Y_EXTENT_MIN <str>] [-USER_Y_EXTENT_MAX <str>] [-USER_GRID_TYPE <num>] [-GET_SYSTEM_SYSTEM_NX
<num>] [-GET_SYSTEM_SYSTEM_NY <num>] [-GET_SYSTEM_SYSTEM_X <str>] [-GET_SYSTEM_SYSTEM_Y <str>]
[-GET_SYSTEM_SYSTEM_D <str>] [-GET_SYSTEM_GRID_TYPE <num>] [-GRID_GRID <str>]
  -GRID:<str>                   Grid
        Data Object (optional output)
  -INPUT:<str>                  Shapes
        Shapes (input)
  -FIELD:<num>                  Attribute
...

Here is an example:

...
# first, convert the contour map to a raster map:
> rsaga.geoprocessor(lib="grid_gridding", module=3, param=list(GRID="contours_buff.sgrd",
+   INPUT="z_contours.shp", FIELD=1, LINE_TYPE=0, USER_CELL_SIZE=dem.pixelsize,
+   USER_X_EXTENT_MIN=elevations at bbox[1,1], USER_X_EXTENT_MAX=elevations at bbox[1,2],
+   USER_Y_EXTENT_MIN=elevations at bbox[2,1], USER_Y_EXTENT_MAX=elevations at bbox[2,2]))
# now extract a buffer distance map (for 'contours') and load it back to R:
# the parameters DIST and IVAL are estimated based on the grid properties:
> rsaga.geoprocessor(lib="grid_tools", module=10, param=list(SOURCE="contours_buff.sgrd",
+ DISTANCE="contours_dist.sgrd", ALLOC="contours_alloc.sgrd", BUFFER="contours_bdist.sgrd",
+ DIST=sqrt(dem.area)/3, IVAL=dem.pixelsize))
> rsaga.sgrd.to.esri(in.sgrds="contours_dist.sgrd", out.grids="contours_dist.asc", 
+    out.path=getwd(), prec=1)
> contours.dist <- readGDAL("contours_dist.asc")
> spplot(contours.dist[1], col.regions=bpy.colors(), scales=list(draw=TRUE), 
+    sp.layout=list("sp.lines", col="cyan", z.contours))
> hist(contours.dist$band1, col="grey")
...

HTH

T. Hengl
http://spatial-analyst.net/wiki/index.php?title=Grid_size_calculator 


> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf
> Of Jonathan Greenberg
> Sent: Sunday, August 02, 2009 8:26 PM
> To: r-sig-geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] Polygon to raster?
> 
> I'm trying to hunt down a function that will take a polygon (derived
> from a shapefile) and "rasterize" it at a given pixel resolution -- any
> hints?
> 
> --j
> 
> --
> 
> Jonathan A. Greenberg, PhD
> Postdoctoral Scholar
> Center for Spatial Technologies and Remote Sensing (CSTARS)
> University of California, Davis
> One Shields Avenue
> The Barn, Room 250N
> Davis, CA 95616
> Cell: 415-794-5043
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list