(python) Creates a new QML file (QGIS style format) with the colors of the strokes equals to the shape fills.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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