Created
May 11, 2016 13:20
-
-
Save luipir/2cd9f01b1d2e881c9f479f55069600ce to your computer and use it in GitHub Desktop.
qgis custom expression to check if feature is selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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