Qgis Function grabbing a value from a list
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
This comment has been minimized.
MarcoDuiker commentedOct 29, 2018
•
edited
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: