6

I converted a raster with 4 classes to a SpatialPolygonsDataFrame, where the features representing a class are not always connected. I used disaggregate (package sp) to get single features.

I now want to get rid of all those features, smaller than 3000 m². I already generated the area with poly.areas(package GISTools) and added the info as attribute to the Shapefile.

The small features should be merged with their surrounding feature.

Has anyone an idea how to solve this? unionSpatialPolygons does only work with IDs, not conditions of attributes.

plot: "small features" in red, numbers indicate the attribute (1-4)

rcs
  • 67,191
  • 22
  • 172
  • 153
Blake
  • 101
  • 1
  • 4
  • What's "their surrounding feature"? Are the "small features" always completely enclosed by another feature? Otherwise which neighbouring feature do you merge it with? Do you need to preserve attributes of the small features? Could you colour the "small features" on your plot so we can see what you are up to? – Spacedman Nov 25 '15 at 14:44
  • Yes, the "small features" are always enclosed, and no the attributes of those small ones do not need to be preserved. In general I want to have fewer features and eliminate "islands" / "fragments". – Blake Nov 25 '15 at 15:37
  • So if you delete the small features and removed holes from any features with holes that would do it? Oh no, you have small features on the edge... They *arent* surrounded... and there's a "2" on the left sandwiched between a 1 and a 3 - who gets that territory? – Spacedman Nov 25 '15 at 16:30
  • Oh well, I see your point! Seems for the edges etc. it'll be way to complicated... – Blake Nov 25 '15 at 18:22
  • Maybe not... Compute the polygon adjacency (spdep::poly2nb) then for each small polygon choose one of its adjacent polys to merge with via maptools::unionSpatialPolygons - can you share your shapefile? – Spacedman Nov 25 '15 at 18:27
  • Ok, I'll try that, thank you! My whole work flow is supposed to be automatic, so I'll have to check if I can implement the functions wisely. – Blake Nov 27 '15 at 10:28
  • The prob is how to automate the choice then - if the small polygon has one neighbour then its trivial, otherwise choose the neighbour with the largest area? – Spacedman Nov 27 '15 at 13:04

0 Answers0