1

After I've loaded a layer from a table in my db I'd like to disable the 'Simplify geometry' (found in Layers/Properties/Rendering) programatically using Python. I've tried several versions of QgsVectorSimplifyMethod.SimplifyHint

current_layer = iface.mapCanvas().currentLayer()
if current_layer:
  try:
    current_layer.setSimplifyMethod(QgsVectorSimplifyMethod.setSimplifyHints(QgsVectorSimplifyMethod.SimplifyHint.NoSimplification))
  catch Exception, e:
      print e

but can't get the usage of QgsVectorSimplifyMethod.SimplifyHint.NoSimplification correct.

2 Answers 2

2

As Jakob pointed out, layer.simplifyMethod().setSimplifyHints(...) doesn't seem to allow changing the simplification method.

In order to change the simplification method for a layer using Python, you can instead create a new QgsVectorSimplifyMethod() object, set the simplification method for that object to NoSimplification, and assign the object to the layer using layer.setSimplifyMethod:

mNoSimplification = QgsVectorSimplifyMethod()
mNoSimplification.setSimplifyHints(QgsVectorSimplifyMethod.NoSimplification)
layer.setSimplifyMethod(mNoSimplification)
0

Perhaps a bug in setSimplifyHints?

>>>current_layer.simplifyMethod().setSimplifyHints(QgsVectorSimplifyMethod.NoSimplification)

>>>int(current_layer.simplifyMethod().simplifyHints()) == QgsVectorSimplifyMethod.NoSimplification
False

>>>int(current_layer.simplifyMethod().simplifyHints()) == QgsVectorSimplifyMethod.GeometrySimplification 
True

After manually removing simplify geometry through the dialog enter image description here

int(current_layer.simplifyMethod().simplifyHints()) == QgsVectorSimplifyMethod.NoSimplification
True

Looks like the simplifyHints does not set the simplification mode. I quess you need to calculate a precise area since you want no geometry simplification. Can you test against your database if simplify does affect any area calculation in QGIS. You can use your PostGIS db to return the area also.

1
  • I would not know how to test it myself. I will however ask the person requesting the disabling of simplify geometry to test this.
    – user28233
    Commented Mar 25, 2014 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.