def processAlgorithm(self, parameters, context, feedback): # pylint: disable=missing-docstring,too-many-locals input_file = self.parameterAsString(parameters, self.INPUT, context) output_file = self.parameterAsFileOutput(parameters, self.OUTPUT, context) mdbtools_folder = ProcessingConfig.getSetting('MDB_PATH') style = QgsStyle() results = {} for type_index, symbol_type in enumerate( (Extractor.FILL_SYMBOLS, Extractor.LINE_SYMBOLS, Extractor.MARKER_SYMBOLS)): feedback.pushInfo('Importing {} from {}'.format(symbol_type, input_file)) raw_symbols = Extractor.extract_styles(input_file, symbol_type, mdbtools_path=mdbtools_folder) feedback.pushInfo('Found {} symbols of type "{}"\n\n'.format(len(raw_symbols), symbol_type)) if feedback.isCanceled(): break unreadable = 0 for index, raw_symbol in enumerate(raw_symbols): feedback.setProgress(index / len(raw_symbols) * 33.3 + 33.3 * type_index) if feedback.isCanceled(): break name = raw_symbol[Extractor.NAME] feedback.pushInfo('{}/{}: {}'.format(index + 1, len(raw_symbols), name)) handle = BytesIO(raw_symbol[Extractor.BLOB]) try: symbol = read_symbol(file_handle=handle) except UnreadableSymbolException as e: feedback.reportError('Error reading symbol {}: {}'.format(name, e)) unreadable += 1 continue try: qgis_symbol = Symbol_to_QgsSymbol(symbol) except NotImplementedException as e: feedback.reportError(str(e)) unreadable += 1 continue style.addSymbol(name, qgis_symbol) if symbol_type == Extractor.FILL_SYMBOLS: results[self.FILL_SYMBOL_COUNT] = len(raw_symbols) results[self.UNREADABLE_FILL_SYMBOLS] = unreadable elif symbol_type == Extractor.LINE_SYMBOLS: results[self.LINE_SYMBOL_COUNT] = len(raw_symbols) results[self.UNREADABLE_LINE_SYMBOLS] = unreadable elif symbol_type == Extractor.MARKER_SYMBOLS: results[self.MARKER_SYMBOL_COUNT] = len(raw_symbols) results[self.UNREADABLE_MARKER_SYMBOLS] = unreadable style.exportXml(output_file) results[self.OUTPUT] = output_file return results
formatted += scan_results_array[line_start + i].color() formatted += char + ' ' + Fore.WHITE if i % 8 == 7: formatted += ' ' formatted += '\t' found_parts = [] for res in scan_results: if line_start <= res.match_start < line_start + 16: found_parts.append( hex(res.match_start)[2:] + ':' + res.color() + res.value() + Fore.WHITE) formatted += ' '.join(found_parts) return formatted start = f.tell() part = f.read(16) print('{}\t{}'.format(hex(start), format_line(start, part))) if len(part) < 16: break print('Scanning complete\n\n\n') with open(args.file, 'rb') as f: symbol = read_symbol(f, debug=args.debug) converter = DictionaryConverter() pprint.pprint(converter.convert_symbol(symbol))
if not args.destination: args.destination = '/home/nyall/Styles/GEO_Surface___Solid_Shades.xml' styles = [(args.file, Extractor.FILL_SYMBOLS)] style = QgsStyle() for (fill_style_db, symbol_type) in styles: print('{}:{}'.format(fill_style_db, symbol_type)) raw_symbols = Extractor.extract_styles(fill_style_db, symbol_type) print('Found {} symbols of type "{}"\n\n'.format(len(raw_symbols), symbol_type)) for index, raw_symbol in enumerate(raw_symbols): name = raw_symbol[Extractor.NAME] # print('{}/{}: {}'.format(index + 1, len(raw_symbols),name)) handle = BytesIO(raw_symbol[Extractor.BLOB]) try: symbol = read_symbol(file_handle=handle) except UnreadableSymbolException: print('Error reading symbol {}'.format(name)) continue qgis_symbol = FillSymbol_to_QgsFillSymbol(symbol) style.addSymbol(name, qgis_symbol) style.exportXml(args.destination)
for symbol_type in (Extractor.FILL_SYMBOLS, Extractor.LINE_SYMBOLS, Extractor.MARKER_SYMBOLS, Extractor.COLORS): print('{}:{}'.format(args.file, symbol_type)) raw_symbols = Extractor.extract_styles(args.file, symbol_type) print('Found {} symbols of type "{}"\n\n'.format(len(raw_symbols), symbol_type)) for index, symbol in enumerate(raw_symbols): print('{}.\t{}\n\tCategory: {}\n\tTags: {}'.format( index + 1, symbol[Extractor.NAME], symbol[Extractor.CATEGORY], symbol[Extractor.TAGS])) handle = BytesIO(symbol[Extractor.BLOB]) if symbol_type == Extractor.COLORS: color_model, color = read_color_and_model(handle) print(color_model, color) else: try: symbol_properties = read_symbol(file_handle=handle) print(symbol_properties) except UnreadableSymbolException as e: print('\t**Symbol could not be parsed!:\n\t{}'.format(e)) unreadable.append(symbol[Extractor.NAME]) print('\n\n') total += 1 print('***Parsed {}/{} symbols'.format(total - len(unreadable), total)) if unreadable: print('Unreadable symbols:\n- {}'.format('\n- '.join(unreadable)))
formatted += scan_results_array[line_start + i].color() formatted += char + ' ' + Fore.WHITE if i % 8 == 7: formatted += ' ' formatted += '\t' found_parts = [] for res in scan_results: if line_start <= res.match_start < line_start + 16: found_parts.append( hex(res.match_start)[2:] + ':' + res.color() + res.value() + Fore.WHITE) formatted += ' '.join(found_parts) return formatted start = f.tell() part = f.read(16) print('{}\t{}'.format(hex(start), format_line(start, part))) if len(part) < 16: break print('Scanning complete\n\n\n') with open(args.file, 'rb') as f: symbol = read_symbol(file_handle=f, debug=args.debug) converter = DictionaryConverter() pprint.pprint(converter.convert_symbol(symbol))
def run(self): """ Start the library generation """ patched_xml = ['S_01_081_0017', 'S_01_081_0018', 'S_14_145_0015', 'S_05_019_0001', 'L_19_006_0008', 'L_25_116_0001', 'S_11_042_0013', 'L_21_105_0002', 'L_21_107_0010', 'L_22_092_0003', 'L_22_092_0008', 'L_22_092_0009', 'L_22_092_0010', 'L_22_092_0011', 'L_22_092_0012', 'P_31_159_0002', 'S_01_081_0010', 'S_01_089_0016', 'S_05_017_0008', 'S_10_041_0004', 'S_13_046_0012', 'S_13_046_0018', 'S_14_048_0008', 'S_18_071_0001', 'P_28_157_0001', 'P_32_160_0001', 'P_33_161_0001'] # Symbols for which it exists a manually modified svg patched_svg = ['P_26_120_0015', 'P_33_172_0001', 'P_26_122_0007', 'P_26_124_0004_1', 'L_20_099_0006', 'L_20_099_0007', 'L_20_099_0009', 'L_20_099_0011', 'P_28_157_0001', 'P_32_160_0001', 'P_33_161_0001'] blobs = [] style = QgsStyle() context = Context() context.units = QgsUnitTypes.RenderMillimeters context.relative_paths = True context.picture_folder = os.path.join( self.output_directory, 'svg') context.convert_fonts = True context.force_svg_instead_of_raster = True context.parameterise_svg = False context.embed_pictures = False a = QApplication([]) for fn in os.listdir(self.bin_directory): file = os.path.join(self.bin_directory, fn) if os.path.isfile(file): blobs.append(file) symbol_name = os.path.splitext(fn)[0] with open(file, 'rb') as f: context.symbol_name = symbol_name symbol = read_symbol(f, debug=False) qgis_symbol = Symbol_to_QgsSymbol(symbol, context) if symbol_name in patched_xml: xml_file = os.path.join( self.patched_xml_directory, symbol_name + '.xml') style.importXml(xml_file) print("Patch symbol {} with {}".format( symbol_name, xml_file)) continue style.addSymbol(symbol_name, qgis_symbol) style.exportXml( os.path.join(self.output_directory, 'libreria.xml')) for svg in patched_svg: svg_src = os.path.join(self.patched_svg_directory, svg + '.svg') svg_dest = os.path.join( self.output_directory, 'svg', svg + '.svg') copyfile(svg_src, svg_dest) print("Patch svg {} with {}".format(svg_dest, svg_src))