Skip to main content
Fixed expression combination (existing expression must be in brackets or the AND clause may change its meaning)
Source Link
ndawson
  • 27.9k
  • 3
  • 62
  • 86

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

Edit:

The above code replaces all expressions entirely. However, if you want to add another expression to an existing one, you can use:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression(rule.filterExpression'({}) + 'ANDAND $id = $atlasfeatureid'.format(rule.filterExpression()))

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

Edit:

The above code replaces all expressions entirely. However, if you want to add another expression to an existing one, you can use:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression(rule.filterExpression() + 'AND $id = $atlasfeatureid')

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

Edit:

The above code replaces all expressions entirely. However, if you want to add another expression to an existing one, you can use:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('({}) AND $id = $atlasfeatureid'.format(rule.filterExpression()))
Edited post in response to comment from OP
Source Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

Edit:

The above code replaces all expressions entirely. However, if you want to add another expression to an existing one, you can use:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression(rule.filterExpression() + 'AND $id = $atlasfeatureid')

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')

Edit:

The above code replaces all expressions entirely. However, if you want to add another expression to an existing one, you can use:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression(rule.filterExpression() + 'AND $id = $atlasfeatureid')
Source Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286

You could also use the following in the Python Console to change all expressions of each rule to $id = $atlasfeatureid:

layer = qgis.utils.iface.activeLayer()
renderer = layer.rendererV2()
for rule in renderer.rootRule().children():
    rule.setFilterExpression('$id = $atlasfeatureid')