Bug report #4189

Simplify feature and Simplify geometries gives incorrect result on valid polygon

Added by Alexander Bruy over 13 years ago. Updated over 11 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:14164

Description

It is impossible to simplify some polygons using QGIS.

When I tried to simplify polygon using Simplify geometries from fTools, polygon was simplified from 825 vertices to 0 and disappears. When I try to simplify this same polygon using Simplify feature tool from Advanced digitizing toolbar I get error "This feature cannot be simplified. Check if feature has enough vertices to be simplified.".

Check geometry says that there are no errors and polygon is valid.

Test shapefile attached.

test-shp.tar.bz2 (12.6 KB) Alexander Bruy, 2011-08-19 06:47 AM

Simplify_problem.zip (5.1 KB) Pieter Roggemans, 2012-06-10 11:09 AM

snapshot3.png - After (173 KB) Daniel Vaz, 2013-07-21 03:30 PM

Associated revisions

Revision b88b76b5
Added by Alexander Bruy over 11 years ago

Merge pull request #755 from ddanielvaz/fix-4189

Fix #4189

History

#1 Updated by Maxim Dubinin over 13 years ago

The reason for wrong behavior is a tiny ring. If it is removed, the polygon is simplified ok.

The polygons with bigger rings simplify ok, but if any polygon has a ring that is smaller than tolerance, it breaks the whole polygon.

I think this is a bug, not sure though if GEOS or QGIS is guilty.

#2 Updated by Giovanni Manghi almost 13 years ago

  • Target version set to Version 1.7.4

#3 Updated by Paolo Cavallini over 12 years ago

  • Target version changed from Version 1.7.4 to Version 1.8.0
  • Affected QGIS version set to master
  • Crashes QGIS or corrupts data set to No

#4 Updated by Pieter Roggemans over 12 years ago

Same problem... If you do a simplify with 2 meter tolerance on the file in attachment one of the two polygons will disappear.

Remarks:
  1. saying that "Causes crash of corruption = No" is kind of odd... as it definitely corrupts data: it was only by luck that I saw some polygons just disappeared... If I wouldn't have noticed, my analysis would have been quite corrupted :-(...
  2. I don't know which libraries are used for this opertation, but I tested it using ogr2ogr version 1.9 and then the simplify works perfectly...

#5 Updated by Giovanni Manghi over 12 years ago

but I tested it using ogr2ogr version 1.9 and then the simplify works perfectly...

can you post the ogr method? I would like to test it and compare with qgis.

#6 Updated by Salvatore Larosa over 12 years ago

@Giovanni: ogr2ogr -simplify 2 -f "ESRI Shapefile" dir/ Simplify_problem.shp

Maxim's thesis is likely correct!

#7 Updated by Giovanni Manghi over 12 years ago

Salvatore Larosa wrote:

@Giovanni: ogr2ogr -simplify 2 -f "ESRI Shapefile" dir/ Simplify_problem.shp

Maxim's thesis is likely correct!

so basically what we need is a better tool to check and fix geometries :)

#8 Updated by Salvatore Larosa over 12 years ago

I confirm this is only a QGIS bug in QgsGeometry::simplify() function!
Same thing for QgsGeometryAnalyzer::simplify()

We need to fix it in core!

OGR and GEOS (ST_Simplify()) work fine!

The only strange thing is that GEOS eliminates the small ring,
instead in OGR it remains as the original layer w/out any change!

#9 Updated by Pieter Roggemans over 12 years ago

In my humble opinion... I think the GEOS ways (removing too small rings) is the most logical one...

If you want to eliminate detail... you know you always loose data in a way, so I think it is more logical to remove the too detailed rings as well...
Eg. If you have a very detailed file you want to show at a low scale, it wouldn't be logical the outer rings are simplified, but there still stay very high-detail (sub)polygons simply because they are that small/detailed...

It implicates that you can loose features as well (if the outer ring is too detailed... but the logic holds here as well... removing details can result in loosing detailed features all together...

The choice is also an option of course... but that's the hard way for implementing and not quite KISS I admit ;-)...

#10 Updated by Paolo Cavallini about 12 years ago

  • Target version changed from Version 1.8.0 to Version 2.0.0

#11 Updated by Tim Sutton about 12 years ago

Added a unit test to replicate this in 1863033 and marked as expected to fail.

#12 Updated by Daniel Vaz over 11 years ago

Instead of use GEOSSimplify using GEOSTopologyPreserveSimplify.

Please give it a try https://github.com/qgis/Quantum-GIS/pull/755

In the snapshot I use tolerance of 2 meters.

Thanks in advance

#13 Updated by Giovanni Manghi over 11 years ago

  • Pull Request or Patch supplied changed from No to Yes

#14 Updated by Alexander Bruy over 11 years ago

Just tested patch, works fine for fTools, but "Simplify Feature" map tool still don't work.

#15 Updated by Alexander Bruy over 11 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF