Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2018 13:53
What would you like to do?
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 />
values_from_list(<i>string</i>, <i>number</i>)
<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
<pre>values_from_list("text", 1)</pre>
components = string.strip('()').split(':',1)
values_list = components[1]
return values_list.split(',')[number - 1]
return None
Copy link

MarcoDuiker commented Oct 29, 2018

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:

to_real(regexp_substr(  "hoek"  , '([-]?\\d+(\\.\\d+)?)[)]'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment