Skip to content

Instantly share code, notes, and snippets.

@macoj
Last active August 29, 2015 14:26
Show Gist options
  • Save macoj/84487bd3258816e216f3 to your computer and use it in GitHub Desktop.
Save macoj/84487bd3258816e216f3 to your computer and use it in GitHub Desktop.
(python) Creates a new QML file (QGIS style format) with the colors of the strokes equals to the shape fills.
import re
def stroke_same_as_fill(file_name, output_file_name):
"""
Creates a new QML file (QGIS style format) with the colors of the strokes equals to the shape fills.
stroke_same_as_fill("/home/marcos/Downloads/teste.qml", "/home/marcos/Downloads/teste2.qml")
:param file_name: filename of QML input file
:param output_file_name: output
"""
with open(file_name, 'r') as input_file, open(output_file_name, 'w') as output_file:
lines = input_file.readlines()
colors = []
for line in lines:
if re.search("<prop k=\"color\" v=\"", line):
colors.append(re.search("[0-9\,]+", line.strip()).group())
color_index = 0
for line in lines:
if re.search("<prop k=\"outline_color\" v=\"", line):
output_file.write(re.sub("[0-9\,]+", colors[color_index], line))
color_index += 1
continue
output_file.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment