Create a gist now

Instantly share code, notes, and snippets.

@NathanW2 /svg.py
Last active Mar 7, 2016

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"?>
<svg>
<g>
<image xlink:href="data:image/jpeg;base64,{0}" height="256" width="320" />
</g>
</svg>
"""
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:
f.write(newsvg)
return path.replace("\\", "/")
@mhugo
mhugo commented Feb 4, 2016

Nice trick here ! :)

@NathanW2
Owner
NathanW2 commented Feb 4, 2016

:)

@d3lmo
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\utils.py", 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