Feature request #6801

add "dissolve only adjacent" dissolve option/tool

Added by Giovanni Manghi over 4 years ago. Updated over 1 year ago.

Status:Open Start Date:12/01/2012
Priority:Normal Due date:
Assigned to:Giovanni Manghi % Done:

0%

Category:Processing/GDAL
Target version:Future Release - Nice to have
Platform: Resolution:
Platform version: Pull Request or Patch supplied:No
Status info: Tag:

Description

It is very common to have to dissolve a polygon layer, but needing to dissolve only geometries that are adjacent.

Right now QGIS dissolves all the features with a common attributes, even the ones that are not adjacent (with a consequent big loss of attribute data).

To tell the truth I would say that is more common the need to dissolve only adjacent features rather than have to dissolve all features with a common attribute.

diss1.png (211.8 kB) Giovanni Manghi, 11/23/2014 10:27 am

diss2.png (174.7 kB) Giovanni Manghi, 11/23/2014 10:27 am

diss3.png (176 kB) Giovanni Manghi, 11/23/2014 10:27 am

History

Updated by Giovanni Manghi almost 3 years ago

  • Priority changed from High to Normal

Updated by Giovanni Manghi almost 3 years ago

  • Subject changed from add "dissolve only adjacent" option to dissolve tool to add "dissolve only adjacent" dissolve option/tool
  • Category changed from fTools to 94
  • Assigned to set to Victor Olaya

adding this options in ftools (or gdal tools) does not make a lot of sense anymore, better add them directly in processing.

Updated by Alexander Bruy over 2 years ago

  • Category changed from 94 to Processing/QGIS

Updated by Giovanni Manghi over 2 years ago

  • File diss1.png added
  • File diss2.png added
  • File diss3.png added
  • Category changed from Processing/QGIS to Processing/GDAL
  • Assigned to changed from Victor Olaya to Giovanni Manghi

To add this tool it can be used a sql only approach, via ogr2ogr/processing, so I should be able to give it a shot.

A possible query is

SELECT
ST_Union(geom) AS geom,
a.diss_field,
null AS oth_field,
SUM AS area_ha
FROM
input a
WHERE
EXISTS (SELECT id_0 FROM input b WHERE b.id_0 != a.id_0 AND (ST_Intersects(a.geom, b.geom))) GROUP BY a.diss_field
UNION
SELECT
geom,
diss_field,
oth_field,
area_ha
FROM
input a
WHERE
NOT EXISTS (SELECT id_0 FROM input b WHERE b.id_0 != a.id_0 AND (ST_Intersects(a.geom, b.geom)))

where "oth_field" is the field to be kept untouched in non dissolved features, "diss_field" is the attribute used to dissolve adjacent features and "area_ha" a numeric field where to eventually compute an aggregation stat in dissolve features (and to be kept untouched in non dissolved features).

A slightly different case is when not only physically isolated features are not meant to be dissolved, but also when features that have only neighbours with a different dissolve field are not meant to be dissolved.

SELECT
ST_Union(geom) AS geom,
a.diss_field,
null AS oth_field,
SUM AS area_ha
FROM
input a
WHERE
EXISTS (SELECT id_0 FROM input b WHERE b.id_0 != a.id_0 AND (ST_Intersects(a.geom, b.geom)) and b.diss_field = a.diss_field) GROUP BY a.diss_field
UNION
SELECT
geom,
diss_field,
oth_field,
area_ha
FROM
input a
WHERE
NOT EXISTS (SELECT id_0 FROM input b WHERE b.id_0 != a.id_0 AND (ST_Intersects(a.geom, b.geom)) and b.diss_field = a.diss_field)

3 pictures are attached to understand better.

Updated by Bernhard Ströbl over 1 year ago

I included this issue in #13654, please consider closing this ticket if appropriate.

Updated by Giovanni Manghi over 1 year ago

Hi Bernhard,

I will add ogr/sql tools regardless of the work being done in native qgis tools, for several reasons: I like the flexibility of having GUI tools purely based on spatial SQL queries and because the tools already available have proven to be overall much quicker than the qgis/ftools counterparts. Cheers!

Also available in: Atom