在 QGIS 中,我們可以在 Symbology > Marker > SVG Marker 設定內建或客製化的向量圖徽(SVG格式)。當我們使用 Inkscape 等向量繪圖程式至作客製化圖徽後,卻發現在 QGIS 中無法更動其填色、外框以及外框粗細(如圖一),這下該怎麼辦呢?其實只要改動 style 中的小參數即可解決!

筆者以 Inkscape 製作了一個 SVG 檔(如圖二)作為範例,繼續閱讀如何修改 SVG 檔案供 QGIS 使用。本範例圖檔以「姓名標示-相同方式分享 3.0 台灣 (CC BY-SA 3.0 TW) 」授權釋出。

自製 SVG 圖徽說明
使用 Inkscape 0.92.4 進行繪圖,檔案中分為兩個圖層(layer):PAT (固定顏色)與 BG (背景、線條粗細可調整)。圖二中,槌子的部分位於 PAT 圖層,黃色圓圈的部分則是 BG 圖層。請將下面的程式碼區塊複製到文字編輯器(比如 Notepad++)後存為 SVG 檔,本例取名為 HammerIcon.svg。
Code1: HammerIcon.svg 檔案內容
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32.896233mm"
height="32.896233mm"
viewBox="0 0 32.896233 32.896233"
version="1.1"
id="svg2279"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="HammerIcon.svg">
<title
id="title2899">HammerIcon</title>
<defs
id="defs2273" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="18.285868"
inkscape:cy="79.885662"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="-8"
inkscape:window-y="32"
inkscape:window-maximized="1" />
<metadata
id="metadata2276">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>HammerIcon</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="BG"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-82.076695,-80.53555)">
<circle
style="fill:#ffd42a;fill-opacity:1;stroke:#806600;stroke-width:0.28935128;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path1447"
cx="98.524811"
cy="96.983665"
r="16.30344" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="PAT"
sodipodi:insensitive="true"
transform="translate(-82.076695,-80.53555)">
<g
id="g1470"
transform="translate(-14.324771,-134.62334)">
<path
sodipodi:nodetypes="ccccsccccccccccccc"
inkscape:connector-curvature="0"
id="path1436"
d="m 123.37128,225.38462 c -3.03209,-2.05718 -8.87548,-5.14233 -17.33286,-4.27428 2.9583,0.98715 6.45025,3.53559 9.67209,5.95066 l -0.27932,0.35841 c -0.73064,0.93747 -1.39883,1.36206 -2.42386,1.5406 -0.60162,0.10479 -1.05906,0.30081 -1.53112,0.65636 -1.44678,1.0897 -3.93041,3.69533 -6.91818,7.25699 l -1.59981,1.90693 2.15676,1.80809 2.15677,1.80808 2.40837,-2.92897 c 2.8532,-3.47043 4.12066,-5.18993 4.94751,-6.70978 0.45407,-0.83464 0.57238,-1.2226 0.56238,-1.84763 -0.0177,-1.10598 0.34345,-1.99712 1.15748,-2.85504 l 0.28055,-0.29588 c 2.34218,1.43059 2.99714,1.67094 5.34369,4.08072 0.71539,0.95754 4.64317,-3.43374 3.67134,-4.6846 -0.72986,-0.55461 -1.43533,-1.21479 -2.27179,-1.77066 z"
style="fill:#b3b3b3;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
transform="scale(0.26458333)"
inkscape:connector-curvature="0"
id="path1466"
d="m 398.06012,909.22113 c -4.0253,-3.37427 -7.50242,-6.28654 -7.72694,-6.47171 l -0.40821,-0.33668 3.86389,-4.60276 c 11.89476,-14.1693 19.77662,-22.66736 25.7921,-27.80849 l 1.41489,-1.20924 0.68057,0.23415 c 1.77073,0.60922 5.53826,2.8998 8.01898,4.87539 1.32558,1.05566 3.18435,2.90164 3.46161,3.4378 0.11367,0.21983 0.26275,0.39968 0.33129,0.39968 0.14682,0 -0.46487,1.24267 -1.46954,2.98544 -3.26203,5.6585 -7.87861,11.7642 -20.77935,27.48193 -3.20408,3.90372 -5.83346,7.10934 -5.84308,7.1236 -0.01,0.0143 -3.31091,-2.73484 -7.33621,-6.10911 z"
style="fill:#0055d4;fill-opacity:1;stroke:none;stroke-width:0.13808925;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 97.047134,95.081304 c 0.96886,0.16705 3.307466,1.9043 3.441096,2.47225"
id="path1464"
inkscape:connector-curvature="0" />
</g>
</svg>
修改 SVG 檔案給 QGIS 使用
QGIS 設定圖例的變數名稱
- 填色: fill
- 外框:outline
- 外框粗細:outline-width
修改步驟
在上面的程式碼中,找到在 62行的 <circle> 標籤:
Code 2: 背景圓圈的部分
<g
inkscape:label="BG"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-82.076695,-80.53555)">
<circle
style="fill:#ffd42a;fill-opacity:1;stroke:#806600;stroke-width:0.28935128;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path1447"
cx="98.524811"
cy="96.983665"
r="16.30344" />
</g>
我們將 style 設定中的「fill」、「stroke」與「stroke-width」取出,並放在 circle 標籤的設定中,並分別指定「fill=”param(fill) #xxxxxx」、「stroke=”param(outline) #xxxxxx”」與「stroke-width=”param(outline-width) N.nnnnn” 」,其中「 #xxxxxx」是 RGB 以 16 進位表示的預設填色(比如網頁顏色碼),「 N.nnnnn 」是預設的粗細。以圖二的 SVG 為例請做下面這樣的更改:
Code 3: 背景圓圈修改過的程式碼
<g
inkscape:label="BG"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-82.076695,-80.53555)">
<circle
fill="param(fill) #ffd42a"
stroke="param(outline) #806600"
stroke-width="param(outline-width) 0.28935128"
style="fill-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path1447"
cx="98.524811"
cy="96.983665"
r="16.30344" />
</g>
請仔細觀察 Code 2 與 Code 3 的差異。
完成後請將檔案儲存並放到 QGIS 的搜尋路徑中。以 QGIS 3.6.3 為例,其路徑在:
C:\Program Files\QGIS 3.6\apps\qgis\svg
可以在此目錄之下自己建立資料夾整理自己的圖徽。
QGIS 更改圖徽
重新開啟一個圖層的 Symbology 設定,在下面選擇圖徽後,就可以發現圖徽已經可以調整顏色與粗細了(圖三與圖四)!

