1

This question already has an answer here:

I would like to dissolve only polygons that are adjacent to one another. Ultimately I would like to start with a raster representing landscape patches and delineate the separate patches. Here is my example, drawing from the raster::rasterToPolygons function in R:

r <- raster(nrow=18, ncol=36)
set.seed(999)
r[] <- runif(ncell(r))
r <- r > 0.7
pol <- rasterToPolygons(r, fun=function(x){x==1})
pol.union <- rasterToPolygons(r, fun=function(x){x==1}, dissolve=T)

plot(r)
plot(pol, add=T)

plot(r)
plot(pol.union, add=T)

Without using the dissolve=T argument in rasterToPolygons, it returns a single polygon for each pixel where r==1 (189 polygons). If I use dissolve=T it dissolves all of these into a single polygon. What I want is something in between where each non-adjacent patch is it's own polygon (it would look like pol.union when plotted but would contain more than one polygon). I believe what I want is to take pol and dissolve only the adjacent polygons.

I realize that this may require some input as to what is considered "adjacent" (i.e., whether only polygons sharing a boundary are considered adjacent or if polygons sharing a single point are considered adjacent).

marked as duplicate by Simbamangu, mgri, Dan C, Mapperz May 3 '17 at 15:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.