Tara,

I think the discussion you refer to was about crop (clip)-ing. That issue
has been addressed (there is a "snap" argument in crop). I could add
something equivalent to rasterize, but for now I think you can already
achieve what you want if you use one additional step: first rasterize the
polygons as lines (every cell touched by a line is included), and than add
the rasterized polygons (all interior cells are included; and "conflict"
cells go to the polygon that covers the center). See the example below:

library(raster)
r <- raster(ncols=90, nrows=45)
p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
p2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0))
p3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0))
pols <- SpatialPolygons( list(  Polygons(list(Polygon(p1), Polygon(hole)),
1), Polygons(list(Polygon(p2)), 2), Polygons(list(Polygon(p3)), 3)))
pols@polygons[[1]]@Polygons[[2]]@hole <- TRUE

r <- raster(ncol=180, nrow=90)
r <- rasterize(as(pols, 'SpatialLines'), r, field=1:3)
r <- rasterize(pols, r, update=TRUE)
plot(r)
# zoom(r)
# plot(pols, add=T)


# another way to express the same thing:
r <- raster(ncol=180, nrow=90)
r1 <- rasterize(pols, r)
r2 <- rasterize(as(pols, 'SpatialLines'), r, field=1:3)
r3 <- cover(r1, r2)


Hth, Robert




On Fri, Mar 2, 2012 at 10:12 AM, Tara Bridwell <tarabridwell@gmail.com>wrote:

> Hi list members,
> I have seen this post
> (
> http://r-sig-geo.2731867.n2.nabble.com/Clip-a-raster-tt5635474.html#a5639429
> )
> but I am wondering if there is a more straightforward way have
> rasterize include ALL of the cells touching a polygon and not just
> those where more than half the edge is covered.
>
> Some code:
>
> # I import the polygon:
> polygon <- readOGR(".","nms",p4s = "+proj=longlat +ellps=WGS84
> +datum=WGS84")
>
> # I read in my raster
> r1 <- readGDAL("raster", p4s = "+proj=longlat +ellps=WGS84 +datum=WGS84")
> r1.r <- raster(r1)
> polygon.r <- rasterize(polygon, r1.r, fun=max)
>
> Thanks,
> Tara
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

