Bug report #14166

Dissolve problems for polygons containing rings

Added by Marie Silvestre about 8 years ago. Updated about 7 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Processing/QGIS
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:22168

Description

I have vectorized a raster layer with 0 and 1 values and obtained a polygon shapefile layer from witch I have removed polygon with the value 0.
I want to dissolve this resulting layer (vectorized.shp) so I use the dissolve tool (from Vector menu) and choose "Dissolve all" as dissolve field.
The result is unexpected (vectorized_regroup.shp): some rings in some polygons are filled but not all... (see attached picture, the layer before dissolve is in black and after dissolve in red).

So I have led my investigation and found out that, by looking at WKT format, dissolve is doing this:
With these features:
Polygon ((coord. of polygon A),(coord. of hole in polygon A))
Polygon ((coord. of polygon B),(coord. of hole 1 in polygon B),(coord. of hole 2 in polygon B))

Dissolve is producing this:
MultiPolygon (((coord. of in polygon A)),((coord. of hole in polygon A)),((coord. of hole in polygon B),(coord. of hole 1 in polygon B),(coord. of hole 2 in polygon B)))

But I would expect this:
MultiPolygon (((coord. of in polygon A),(coord. of hole in polygon A)),((coord. of hole in polygon B),(coord. of hole 1 in polygon B),(coord. of hole 2 in polygon B)))

It seems that the dissolve tool cannot deal properly with rings when coordinates are "aligned" (due to the raster). Indeed I have moved one node of a ring and the dissolve tool works fine afterwards (vectorized_bis.shp and vectorized_bis_regroup.shp)...

(I am running QGIS 2.13.0-78 with GDAL/OGR 1.11.3-1.)

dissolve_pb.zip (34.2 KB) Marie Silvestre, 2016-01-25 05:43 AM

vectorized_pb.PNG (41.8 KB) Marie Silvestre, 2016-01-26 01:12 AM

vectorized_bis_no_pb.PNG (40.5 KB) Marie Silvestre, 2016-01-26 01:12 AM

vectorized_ter_no_pb.PNG (25.8 KB) Marie Silvestre, 2016-01-26 01:12 AM

History

#1 Updated by Martin Dobias about 8 years ago

  • Status changed from Open to Feedback

Hmmm I am not sure I understand the problem you describe here. In your case, from vectorized.shp, Dissolve simply makes a union of all geometries into one multipolygon. I have compared the areas in vectorized.shp and vectorized_regroup.shp and they are the same. WKT also seems to be correct (holes are represented as internal rings in the polygons within that one multipolygon).

#2 Updated by Marie Silvestre about 8 years ago

Let's try another way to describe the problem. 3 images are attached:

vectorized_pb.PNG : the dissolve tool creates a polygon where there should be a ring and thus the areas of vectorized.shp and vectorized_regroup.shp are not the same (nearly 15000m² of difference)!

vectorized_bis_no_pb.PNG : with a slight change of coordinate for one node (of a ring), the dissolve tool works perfectly.

vectorized_ter_no_pb.PNG : with only one polygon containing a ring, the dissolve tool also works perfectly.

#3 Updated by Martin Dobias about 8 years ago

Thanks. This is interesting... On my system, vectorized_regroup.shp shows up in QGIS with a hole where it should be (the ring is not filled), and the total area is also 1301615 just like with vectorized.shp. This is on Linux 64bit / OGR 1.10.1 / QGIS master. Maybe there is a difference in reading shapefiles between different versions of OGR library.

#4 Updated by Giovanni Manghi about 8 years ago

  • Status changed from Feedback to Open

#5 Updated by Giovanni Manghi about 7 years ago

  • Category changed from 44 to Processing/QGIS

#6 Updated by Giovanni Manghi about 7 years ago

  • Resolution set to fixed/implemented
  • Status changed from Open to Closed

The (native QGIS) dissolve tool (now only in Processing) returns the right result in QGIS 2.18.2.

Also the areas of input and dissolved layer are matching almost perfectly (the below values maybe differ for some rounding did by the "group stats" plugin):

original 1301615.96

dissolved 1301615.97607422

Also available in: Atom PDF