Skip to main content
3 of 4
Two minor corrections.
James
  • 81
  • 3

Thanks to all of you. There are some great tips here and they pointed me in the right direction but none addressed my specific issue so I'll add what I figured out to the pot. Since there doesn't seem to be one right answer for every case, I'd like to first offer a suggestion for testing your results as quickly as possible.

Fast Edit Testing

  • Temporarily move all of your svg icons out of the QGIS svg folder.
  • Make a copy of the svg file you wish to work on read only so you don't overwrite it and put an editable version of it in the QGIS svg folder.
  • Open QGIS, load a point layer to work with, open the layer properties and select "SVG marker".
  • You may additionally wish to right-click on an svg file and temporarily set the default "Open with" program to Notepad so you can just double-click on them to edit them in Notepad.

With this setup you can immediately see how QGIS responds to your edits. Leave the svg file open in Notepad and the properties pane open in QGIS. To test the results of an edit, just hit Ctrl+S to save it in Notepad and switch over to QGIS. To reload the svg, change the symbol layer type to anything else, then change it back to SVG marker. There's also only one in there so you have no trouble finding it. I tested dozens of edits very quickly like this. If you have any trouble getting the svg back to source form after an edit you can just delete it and make another copy.

Making SVG Icon Editable

The problem I had was that the specific icon I was working on didn't have the words "style" or "fill" anywhere so I had trouble figuring out where to put the parameter line. The Inkscape trick described by Martina solved this problem but I have a bunch of them to do and I didn't want to open and save each in Inkscape so I decided to attempt trial and error. Looking at the code I could see that the version info and metadata was at the top and the shape instructions were at the bottom enclosed in quotation marks that were bounded at the beginning by <g><path d= (some have <g><g><path d=) and at the end by /></g></svg>. After a little experimenting I figured out that putting the parameter line between path and d= worked but the icon was invisible in the selector pane and the icon in the preview pane at the top was entirely filled in black. The invisible icon issue seems to have been a bug. I fixed it by adding an opacity parameter that I will describe below. It turned out that the black fill was just because the icon was only 4mm and it was filled by just the outline. To fix this I bumped the icon size up to 10mm (in QGIS) and bumped the outline down to 0.1 (in Notepad).

Summary

If your icon doesn't have the words "style" or "fill" anywhere, but it does have this line <g><path d= (or <g><g><path d=) right before the shape instructions you should be able to add the edit parameters by replacing the above line with <g><path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d=

If the border is too thick, you can shrink it by changing the last number to a fraction e.g. <g><path fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 0.5" d=

If you wish to make your icon semitransparent you can do so by changing the above line to this one <g><path style="opacity:0.5;fill:param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1" d=. The opacity value can be from 1 (fully opaque) to 0 (fully transparent) and you can use hundredths or even thousandths for additional precision (e.g. 0.01). The same rule goes for border thickness.

If you have a lot of them to edit, you can find batch files here on StackExchange to automate the search and replace process.

James
  • 81
  • 3