4

There is the possibility to save the style of a layer in a geopackage:

Layer.saveStyleToDatabase

This style can be read by QGIS without additional code. But is there a way for QGIS to read SVG symbols from a gpkg?

I could write the SVG by code, but reading should be done without additional code.

Mike -EZUSoft-
  • 1,367
  • 1
  • 8
  • 18
  • Do you know https://changelog.qgis.org/en/qgis/version/3.4-LTR/#svg-files-can-be-embedded-projects-symbols ? – etrimaille Mar 19 '20 at 08:52
  • 1
    Which version QGIS are you using? – MortenSickel Mar 19 '20 at 09:03
  • @etrimaille: I didn't know it yet. Would be a partial solution, but one would have to deliver an additional (proprietary) file for the GeoPackage. – Mike -EZUSoft- Mar 19 '20 at 09:18
  • @ MortenSickel: The version is not so important. I am looking for a way to exchange data with others with little effort – Mike -EZUSoft- Mar 19 '20 at 09:20
  • 1
    The version is always important. I see many people working with QGIS 2 (not even 2.18), QGIS 3.4.0... nowadays! I'm giving you an answer using QGIS 3.4, maybe you are not using it? How can I guess?And in your question, you are mentioning only SVG, not additional proprietary data. – etrimaille Mar 19 '20 at 11:14
  • I am looking for a future-proof solution. So if this only works from the latest version, this is also a solution.:-)

    All data in one file (GPKG) would be optimal for me.

    – Mike -EZUSoft- Mar 19 '20 at 12:22
  • @etrimaille: That seems to be the solution. The SVG is not only embedded in the project file, but also in the GeoPackage. Now I just have to find / create the right code. – Mike -EZUSoft- Mar 19 '20 at 14:14

1 Answers1

6

I was very interested by myself, to find out how we can package a QGIS project with all external dependencies inside a GeoPackage database. With the help of the "indispensible" expression editor, it's possible to reference SVGs/images stored in a BLOB column and base64 encode on-the-fly.

  1. Create a GPKG layer (i.e. "svg") with 2 columns (name:text,image:binary[blob])

enter image description here

  1. Store your SVG images in the layer "svg" (click on the "..." button to embed the SVG):

enter image description here

  1. Reference the SVG symbols in your vector layer (i.e. table "locations", column "type")

enter image description here

  1. Use SVG Marker styling with the following expression to display your SVG symbols

'base64:'|| to_base64(attribute(get_feature( 'svg','name',"type"),'image'))

enter image description here

  1. Praise the Qt developer, who has added support for inline SVGs and inline images!

enter image description here

christoph
  • 5,605
  • 1
  • 20
  • 34
  • 2
    To be honest, Base64 encoding is not really necessary. See my answer here: https://gis.stackexchange.com/questions/374223/using-embedded-svg-symbol-in-multiple-layers – christoph Mar 09 '21 at 16:35