Many topics are talking about merging polygons based on their common attributes, but few (or none) give a real answer to location-based merging problem.
Some polygons are adjacents but belong to different entities. I want them to merge when they touch and stay as they are if they don't. Then, I want to extract the area of the new entities out of it.
Due to the large size of the maps, I'm working on Grass.
To solve the problem, I first made a tiny buffer:
grass_util.g('v.buffer', input='map', output='map_buffer', type=area distance=0.001)
My output is this one:
Everything looks pretty good, except that making a buffer brings the entities to merge into the one same entity (as displayed by the attr table that I can display here due to my small reputation). More precisely, the number of entities is almost the same, a bit less, the ones that didn't merge plus the new merged ones, but they are all affected "1" in the only category: "cat".
So we still have our different polygons, different entities, but they are merged.
Following this, when I try to add a new column and fill it with geometrics (my area in ha):
grass_util.g('v.db.addcolumn' map='map_buffer' col="area int") grass_util.g('v.to.db', map='map_buffer', option=area, column=area, unit=h)
It lamely fails ! The area isn't calculated for each entity and attributed to it. It is calculated for the whole package, and every entity gets the area of the whole.
I have to say that I don't really see how to get this thing sorted. I tried dissolve, v.clean, v.build, multiple to one and one to multiple, I tried to deconstruct the polygones to lines and to reconstruct them again.
An option which need the processing module that I don't have yet is to use this command:
processing.runalg('qgis:exportaddgeometrycolumns', input, calc_method, output)
which works when I try on a small area in Qgis Gui.
The question is twofold:
- Find an other way to merge the adjacent polygons based on their location (to avoid the destructive buffer)
- Find a way to get back my entities and retrieve their personal areas.