The figure shows a plot of numerous polygons (zoom in) made from a raster file by
require(sp)
require(raster)
pol100 <- rasterToPolygons(r, fun=function(x){x==1}, dissolve=FALSE)
There polygon has 2059 features
> pol100
class : SpatialPolygonsDataFrame
nfeatures : 2059
extent : 254358.6, 268808.1, 2619318, 2642087 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=46 +datum=WGS84 +units=m +no_defs
nvariables : 1
names : value
min values : 1
max values : 1
Each of the small polygons can be explored/plotted individually
#if want to plot a particular polygon
plot(pol100[[1]][[500]])
#if want to know the area of a particular polygon (say polygon#100)
#(all polygons are in fact of same size)
pol100@polygons[[100]]@area
I want to know if there is any automated way to merge the nearest neighbor polygons? Looking at the figure tells that the process will create approximately 15-20 large polygons, for instance. Thanks in advance.
plot(coordinates(out[[1]][[200]]), type="l")
?unionSpatialPolygons {maptools}
and theID=
argument to base spatial union on... I did something similar in the answer of this question; gis.stackexchange.com/questions/82667/…