Skip to content
Prev 24205 / 29559 Next

problem with rasterToPolygons x worldclim

On Thu, 7 Apr 2016 at 00:33 Michael Sumner <mdsumner at gmail.com> wrote:

            
Sorry, forgot the code!

library(raster)

r<-getData('worldclim', var='bio', res=10)$bio1

e <- extent(-140,-100, 50, 60)

xx <- crop(r,e)

## buffer out a little
xx2 <- extend(xx, extent(xx) + res(xx) * 4, value = NA_real_)

## set missing to less than interval
xx2[is.na(xx2)] <- cellStats(xx2, min)
## now contour
cl <- rasterToContour(xx2 > 40 & xx2 < 60, level = 1)

pp <- rgeos::gUnionCascaded(rgeos::gPolygonize(cl))
pp
plot(pp, col = "grey")
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia