How to dissolve polygons spatially in GRASS GIS
You can use the v.dissolve module to dissolve polygons (areas in GRASS terms) by attributes, but what if you don’t have any common attributes and want to dissolve them spatially? You cannot find one module that just does spatial dissolving in GRASS GIS. However, it can be done!
I wanted to remove small offshore islands that are not entirely one country from the GADM 3.6 data. The rationale behind this task is to leave islands-only countries untouched, but remove small islands that are part of an inland or bigger island country. This task was tricky because I could not just remove small areas because those areas can be inland areas. As far as I know, there are no modules that can identify offshore areas that do not touch other neighbor areas in the same layer.
In this article, I’ll just discuss spatial dissolving to keep it simple and focused. Figure 1 shows the original GADM 3.6 vector layer. I want to dissolve all the countries to create a new spatially dissolved layer.
The first step is to add a new integer column named
v.db.addcolumn map=gadm36 column='dissolve int'
Now, we can dissolve all the areas into one category.
v.db.update map=gadm36 column=dissolve value=1 v.dissolve input=gadm36 column=dissolve output=gadm36_dissolved
Drop the dummy
v.db.dropcolumn map=gadm36 column=dissolve
Is it this easy? Not yet because now all the areas in the dissolved layer have only one category and there are no ways to delete small islands because we cannot select them by category. Figure 2 shows the dissolved layer, but it only has one category for all the areas.
To address this problem, we just need to recreate categories for all the features. First, delete the single category from them.
v.category input=gadm36_dissolved output=gadm36_dissolved_nocats option=del
Then, add unique categories to them.
v.category input=gadm36_dissolved_nocats output=gadm36_dissolved_cats option=add
Figure 3 shows the final categorized layer.