Created
February 21, 2018 13:53
-
-
Save MarcoDuiker/3f9895dfc8e2978fca3715852f635e34 to your computer and use it in GitHub Desktop.
Qgis Function grabbing a value from a list
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
from qgis.core import * | |
from qgis.gui import * | |
@qgsfunction(args='auto', group='Custom') | |
def values_from_list(string, number, feature, parent): | |
""" | |
Takes the n-th value from a list in a field where the list is | |
written like: (3:value1, value2,value3). Such lists are often a | |
result of importing gml. <br /> | |
<h3>Syntax</h3> | |
values_from_list(<i>string</i>, <i>number</i>) | |
<h3>Arguments</h3><br/> | |
<i>string</i> The string containing the list in format like (3:value1, value2,value3) <br/> | |
<i>number</i> The index number of the value in the list to return | |
<h3>Examples</h3> | |
<pre>values_from_list("text", 1)</pre> | |
""" | |
components = string.strip('()').split(':',1) | |
values_list = components[1] | |
try: | |
return values_list.split(',')[number - 1] | |
except: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using a function like this for openbareruimtelabel from the BGT, then the following regex based expression grabs the last value as it should to use the right rotation for a label: