Skip to content

Instantly share code, notes, and snippets.

@luipir
Created May 11, 2016 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luipir/2cd9f01b1d2e881c9f479f55069600ce to your computer and use it in GitHub Desktop.
Save luipir/2cd9f01b1d2e881c9f479f55069600ce to your computer and use it in GitHub Desktop.
qgis custom expression to check if feature is selected
"""
Template function file. Define new functions using @qgsfunction.
When using args="auto" you may define a new variable for each value for the function.
feature and parent must always be the last args.
To pass a any number of args into a function use args=-1 the first
variable will then be a list of values.
"""
from qgis.core import *
from qgis.gui import *
@qgsfunction(1, 'Custom')
def isSelected(vectorName, feature, parent):
if not vectorName:
return
layer = QgsMapLayerRegistry.instance().mapLayersByName(vectorName[0])
if not layer:
return
layer = layer[0]
selectedIds = layer.selectedFeaturesIds()
if feature.id() in selectedIds:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment