Bug report #14166
Dissolve problems for polygons containing rings
|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|
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.)
#1 Updated by Martin Dobias over 4 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 over 4 years ago
- File vectorized_ter_no_pb.PNG added
- File vectorized_pb.PNG added
- File vectorized_bis_no_pb.PNG added
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 over 4 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.
#6 Updated by Giovanni Manghi over 3 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):