Feature request #6801

add "dissolve only adjacent" dissolve option/tool

Added by Giovanni Manghi over 11 years ago. Updated almost 7 years ago.

Status:Open
Priority:Normal
Assignee:Giovanni Manghi
Category:Processing/GDAL
Pull Request or Patch supplied:No Resolution:
Easy fix?:No Copied to github as #:15949

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 (212 KB) Giovanni Manghi, 2014-11-23 10:27 AM

diss2.png (175 KB) Giovanni Manghi, 2014-11-23 10:27 AM

diss3.png (176 KB) Giovanni Manghi, 2014-11-23 10:27 AM

History

#1 Updated by Giovanni Manghi almost 10 years ago

  • Priority changed from High to Normal

#2 Updated by Giovanni Manghi over 9 years ago

  • Category changed from 44 to 94
  • Subject changed from add "dissolve only adjacent" option to dissolve tool to add "dissolve only adjacent" dissolve option/tool
  • Assignee 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.

#3 Updated by Alexander Bruy over 9 years ago

  • Category changed from 94 to Processing/QGIS

#4 Updated by Giovanni Manghi over 9 years ago

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

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.

#5 Updated by Bernhard Ströbl over 8 years ago

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

#6 Updated by Giovanni Manghi over 8 years 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!

#7 Updated by Giovanni Manghi almost 7 years ago

  • Easy fix? set to No

Also available in: Atom PDF