[R-sig-Geo] Vector to raster conversion...

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 30 17:43:05 CET 2009


On Fri, 30 Jan 2009, Jonathan Greenberg wrote:

> Question:
>
>   If I have a polygon shapefile, and I want to rasterize each polygon given 
> a certain grid cell resolution, is there a way to do this completely within 
> R?  I'm considering porting our vector<->raster bridge "starspan" 
> (http://starspan.casil.ucdavis.edu/doku/doku.php) to R code, but this is a 
> critical portion of the algorithm.  If the answer is "yes" -- does that 
> answer include "weird" polygons like donuts?

Jonathan,

In principle, the overlay() method in the sp package for "SpatialPolygon" 
and "SpatialPoints" objects, specifically the:

sp:::pointsInSpatialPolygons

function is where to start. The underlying assumption is that raster cell 
support can be cast to cell centre point support. This function first 
finds candidate polygons by testing polygon bounding boxes, then hands off 
to:

sp:::pointsInPolys2

which calls:

sp:::pointsInPolygons

Here you can see that hole handling at the per-ring stage is attempted, 
but does depend on the imported rings declaring their hole status 
correctly. It is possible to use checkPolygonsHoles() in maptools, but 
this takes time.

Hope this helps, porting starspans would be very welcome - I guess users 
at the moment use it loose-coupled by reading and writing files.

The overlay methods are open to optimisation (you'll see that bits of 
sp:::pointsInSpatialPolygons moves heavier-lifting out to C).

Roger

>
> --j
>
>

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




More information about the R-sig-Geo mailing list