0

I have a raster (say r) and a polygon shapefile (say s, containing many polygons). I want to convert the pixelated r to mean of s boundaries. And I need these boundary means as another raster file.

What I have now is the extract function:

rmean <- extract(r,s,fun=mean,df=TRUE)

but, I am not able to convert this into a raster.

Thanks in advance for help.

1
  • Have you tried with raster::rasterize() function? if so, did it work? It would be easier to help you if you give us a reproducible example Jun 11 '20 at 15:21
1

Assign the values to the polygons and then rasterise the polygons on that value.

Using polys and r from example(extract):

> polys$r = extract(r, polys, fun=mean)
> rp = rasterize(polys, r, "r")
> plot(rp)

enter image description here

1
  • Perfect, thanks!
    – nube719
    Jun 11 '20 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.