2

I'm attempting to follow along with this tutorial on using web images as markers within QGIS. I'm using static web-linked images, not webcams as in the tutorial.

The code seems to be working correctly, except the svg that is generated does not render within QGIS.

This is the code i'm using in the symbology function editor, taken from the above tutorial:

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 version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <g>
    <image xlink:href="data:image/jpeg;base64,{0}" />
  </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:\test\{0}.svg".format(name)
    with open(path, 'w') as f:
        f.write(newsvg)
    return path.replace("\\", "/")

When I attempt to open the generated svg file directly in a browser, it also does not render, just showing me a blank page.

Any suggestions? Are there any better methods to use images as markers within QGIS in the 2 years since this tutorial was posted?

  • 1
    Not sure if "better" but there are other ways to display images: gis.stackexchange.com/questions/237156/… and also gis.stackexchange.com/questions/123675/… – csk Nov 14 '18 at 18:06
  • Is the "photo" widget still avaiable in qgis 3.4? I attempted to follow the tutorial in your link, but it looks like the photo widget used there no longer exists. – BogBody Nov 14 '18 at 18:27
  • 1
    I assumed it was, but it's not there anymore, and I'm not sure where it went. It's no longer listed in the edit widget section of the manual, but I don't see any mention in the changelogs about removing this feature or moving it to another location. I suggest asking a new question along the lines of "Where's the photo widget in QGIS 3.4?" – csk Nov 14 '18 at 18:42
  • Thanks. I think it might have been replaced by the attachment -> image/web image function. Still not an ideal solution for what i'm trying to do, though, but thank you very much for trying to help, i appreciate it. – BogBody Nov 14 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.