forked from kathicks/ocha_icons
-
Notifications
You must be signed in to change notification settings - Fork 4
/
convert_to_qgis.py
38 lines (28 loc) · 1.07 KB
/
convert_to_qgis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import xml.etree.ElementTree as ET
import helpers
sourceDir = '../original_un_blue_versions/svg'
destDir = '../qgis_versions/svg'
svgNs = 'http://www.w3.org/2000/svg'
ET.register_namespace('', svgNs)
files = os.listdir(sourceDir)
tags = ('path', 'polygon', 'circle', 'rect')
uriPrefixedTags = ['{{{0}}}'.format(svgNs) + s for s in tags]
qgisStylingAttributes = {'fill': 'param(fill)',
'stroke': 'param(outline)',
'stroke-width': 'param(outline-width) 0'}
for file in files:
sourceFile = os.path.join(sourceDir, file)
destFile = os.path.join(destDir, file)
#print(sourceFile)
#print(destFile)
tree = ET.parse(sourceFile)
root = tree.getroot()
enlargedViewbox = helpers.enlargeViewboxSize(root.get('viewBox'), 2)
root.set('viewBox', enlargedViewbox)
for element in root.iter():
if element.tag in uriPrefixedTags:
element.attrib.pop('class', None)
element.attrib.update(qgisStylingAttributes)
#print(element.attrib)
tree.write(destFile, encoding='utf-8')