Create a gist now

Instantly share code, notes, and snippets.

@NathanW2 /
Last active Mar 7, 2016

What would you like to do?
Web images as QGIS markers
import requests
import base64
@qgsfunction(args='auto', group='Custom')
def show_camera(feed, feature, parent):
svg = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<image xlink:href="data:image/jpeg;base64,{0}" height="256" width="320" />
data = requests.get(feed, stream=True).content
name = feed[-16:]
b64response = base64.b64encode(data)
newsvg = svg.format(b64response).replace('\n','')
path = r"C:\temp\camera\{0}.svg".format(name)
with open(path, 'w') as f:
return path.replace("\\", "/")

mhugo commented Feb 4, 2016

Nice trick here ! :)


NathanW2 commented Feb 4, 2016


d3lmo commented Mar 7, 2016

Cool, but it don't work for me.. When i try to test the function qgis tell me:

Traceback (most recent call last):
File "", line 1, in
File "C:/PROGRA1/QGISLY1/apps/qgis/./python\qgis\", line 572, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named requests

where am I wrong?

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