Do you want to create your custom SVG marker for QGIS map? Map markers are also called map symbols or map labels. QGIS comes with an extensive number of markers for you to use in your maps. However, there are always instances when none of these inbuilt symbols fit the theme of your map. In such case you’ll have no option but to create your custom SVG marker for using Inkscape -or any other graphic design software of your choice. In this article you’ll learn how to create your custom -and editable- map label using Inkscape.
Inkscape, like QGIS, is a free and open-source software (FOSS). Inkscape is a vector graphic design software. It has all the features you need to create any map label of your choice. This tutorial will show you how to create editable marker(s) for your map using Inkscape. It will also show you how to import the marker(s) into QGIS.
This tutorial doesn’t cover how to draw lines, shapes and curves in Inkscape. So, if you are new to graphic design or you have never used Inkscape then you might want to learn the basics of graphic design and how to design with Inkscape.
Message to non-Inkscape users
This tutorial will be based on Inkscape, so if you are not able to follow along in your software then you might want to switch to Inkscape. Those who already know how to use a design software such as illustrator can simply follow along. Also, ensure that your design software is able to save files in the SVG format. I’ve once read that Corel Draw has poor support for SVG. In fact, I once designed a business card for a friend -in SVG format- only for him to be unable to print it because the printing guys only use Corel Draw.
How to create custom SVG marker for QGIS using Inkscape.
That said, you can get your own free copy of Inkscape here. I’m assuming that you already have QGIS installed on your computer, if not then here’s the download link. Lastly, if you already have the two -Inkscape and QGIS- installed on your computer then please follow along as we create our custom SVG markers with Inkscape and import it to our map in QGIS.
1. Launch Inkscape
Once you have downloaded and installed Inkscape on your PC, the next step is to launch the software. Simply double click on the Inkscape logo to launch it -just as you would launch a typical software on windows or mac.
2. Draw your marker
Draw your icon or symbol using the Inkscape drawing tools. Don’t bother about the size of your drawing.
Also, ensure that you align your drawing to the centre of your page.
Lastly, Inkscape saves in the SVG format –which is a vector format- so the length or width of your drawing has no significance, at least not now.
3. Slim-fit your page to your drawing
Now that you have drawn your map symbol. The next step is for you to set the page size of Inkscape to the size of our drawing. If you don’t do that QGIS will think that your whole canvas is your marker. Trust me you don’t want that. However, you’re free to experiment and checkout the ugly result.
Those who are familiar with Inkscape might think that they need to go to File ⇒ Document Properties, manually input the page size then centre their drawing on the page. While that might work (fine or not), it’s an unnecessarily long journey. Inkscape has a cool feature that lets you automatically resize your image to the size of our drawing. I call it slim-fitting your page to the size of your image.
To access this feature follow these two simple steps:
- Click and drag you mouse across the screen to select the object(s) that you wish to use as your custom marker in QGIS.
- Go to Menu⇒ Edit ⇒ Resize page to selection. Alternatively, you can use the Ctrl+Shift+R shortcut on your keyboard and your page will resize itself to fit the objects you have selected.
4. Save your drawing to SVG
Now that you’ve successfully created your map symbol and slim-fitted your page to the size your map marker. The next step is for you to save your drawing as SVG. SVG is the abbreviation of SIMPLE VECTOR GRAPHICS. It is a free and open source format for saving and sharing graphics design. You can learn more here.
Go to File ⇒ Save as or use the Shift+Ctrl+S shortcut on your keyboard to open the save dialogue box.
A dialogue box will appear. Here you will choose the directory you wish to save your drawing to, the name you wish to give your icon and the format you wish to save it to.
SVG is the default format that Inkscape works with, rather Inkscape has its own SVG format. Just as QGIS works with QGD, Photoshop with PSD and Microsoft Word works with DOCX so also Inkscape saves, reads and shares with the SVG format.
To be on the safer side, I advise you not to save in the Inkscape SVG format. So please choose the option next to it; PLAIN SVG. Choose PLAIN SVG, then click on save.
5. Make your marker readable for QGIS
Your marker is now ready to be used in QGIS. However there is a ‘but’, QGIS cannot edit the fill colour and stroke colour. So also QGIS cannot read the stroke width. As a result, QGIS will not give you the option to edit any of the above properties of your map symbol.
This means you have to repeat all the steps above –from 1 to 4- every time you feel like changing the size or colour of your label. That is a tedious task indeed.
If you are new to Inkscape, stroke means the outline of a shape and fill means the colour of the inside. The rectangle above, for example, has a red fill and blue stroke.
To make your SVG marker editable in QGIS you need to access the code of the SVG and edit some lines. Don’t panic yet, it’s something very simple and straight forward. But before proceeding it is a good idea to keep a duplicate of the file just in case something goes wrong.
I believe that notepad++ is better than the traditional notepad for this task. Alternatively, you can use the text editor that you’re used to.
- Open the directory where you saved your plain SVG.
- Right click and choose edit with notepad++.
- Now, look for the line of code that begins with style. You can search for it by using CTRL+F and entering “style” in the text box.
Select and delete the line of code that begins with “style”.
It should look like this:
Then replace it with this line of code:
fill="param(fill) #fff" stroke="param(outline) #000" stroke-width="param(outline-width) 1"
Now click CTRL+S to save your edit.
6. Import you marker to QGIS
You are almost done. This is the final step.
Launch QGIS and add your shapefile to the QGIS canvas. Right click on the layer of your choice in the layers panel and choose properties. Then click on the symbology icon.
Click on the ‘symbology layer type’ drop down menu and choose SVG markers. QGIS will load the inbuilt SVG markers.
You want to use your custom marker which you created in Inkscape not the inbuilt markers. To do this:
Scroll down to the bottom of the dialogue box and click on the button with three dots.
Navigate to where you saved your custom SVG marker which you edited with notepad++ (or your favourite text editor).
Select the SVG icon and click on open. Your marker should now appear in the preview area. You can change the fill colour, stroke colour and width to your taste.
Ensure that you set your vertical and horizontal anchor points to Vcenter and Hcenter respectively.
That’s it. You’ve added your custom SVG icon which you made in Inkscape to QGIS.
Were you able to add your custom SVG icons which you made in Inkscape to QGIS successfully? Did I omit any part or didn’t explain something clearly? Also, if you encountered any challenges kindly let me know and I’ll be glad to give a helping hand.
I’ll be glad to hear your feedback.