Skip to content

Instantly share code, notes, and snippets.

@trolleway
Last active March 19, 2016 13:12
Show Gist options
  • Save trolleway/a712f34d2894c5d335b3 to your computer and use it in GitHub Desktop.
Save trolleway/a712f34d2894c5d335b3 to your computer and use it in GitHub Desktop.
Python code. Search in hstore values for function editor in QGIS
"""
Define new functions using @qgsfunction. feature and parent must always be the
last args. Use args=-1 to pass a list of values as arguments
"""
from qgis.core import *
from qgis.gui import *
import re
'''
Example: getTag("other_tags",'railway') -> 'platform'
'''
@qgsfunction(args="auto", group='Custom')
def getTag(attr, tag, feature, parent):
tag=tag
attr=attr
regexp='"'+tag+'"=>"(.+?)"'
re_output=re.search(regexp,attr)
if re_output:
result = re_output.group(1)
else:
return ''
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment