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

Robert Hijmans r.hijmans at gmail.com
Mon Feb 2 12:21:30 CET 2009


Dear Jonathan,

The raster package (under development at R-forge) has pointsToRaster,
linesToRaster and polygonsToRaster. The latter function takes an sp
polygons object and a raster RasterLayer of any resolution. It should
handle polygon holes (if they are flagged as such in the sp polygons
object). Roger pointed out last week that it would be good to compare
the results of the algorithm in raster with that of starspan. Even if
the results were the same, there is a lot to say for a C based
algorithm. Particularly if it can do row by row (or other blocks)
processing at a higher speed. I would be interested in using that in
the raster package and please contact me directly about that if you
wish.

Robert



On Sat, Jan 31, 2009 at 12:43 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> 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
>
> _______________________________________________
> 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