I have vectorized raster as in the image. This is actually 1419 polygons in
SpatialPolygons class object.
I'm looking for a method which would allow me to extract the one most external polygon (boundary shape). I've found
concave method which works for 95% of cases but not in this particular one. As follows the code:
sfn <- sf::st_as_sf(the_polygon) sfu = sf::st_union(sfn) gpts = sf::st_coordinates(sfu) gmat <- matrix(c(gpts[,1], gpts[,2]), ncol = 2)
I can adjust parameters:
cm = concaveman::concaveman(gmat, 0.5, 1) chp = SpatialPolygons(list(Polygons(list(Polygon(cm)), ID=n)))
So there's no optimal shape, I've tested values between those 2 and further as well. The second parameter doesn't make much - it just smoothes the lines.
I'd like to ask from your experience what kind of approach I'd take? For example, if I had a function which fills the outside area, then selects "negative" and makes borderline and that border would be good approximate of what I need. Notice it's a vector(s). Have anyone some idea? In terms of fill the vectors area what libraries I'd choose?
Incredible things happen: I've fit this almost ideally using
concaveman(gmat, 0.01, 2.2) - just tested with
"bruteforce plot". So, in this case, answer been partially found.