aRT 1.7-1

aRT 1.7-1

Novo

Corrigir

R-SIG-GEO demand

rasterize polygons

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? Roger: 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)