def _svgMarkerSymbol(name, sprites): #TODO: see if there is a built-in sprite with that name with open(sprites + ".json") as f: spritesDict = json.load(f) rect = QRect(spritesDict[name]["x"], spritesDict[name]["y"], spritesDict[name]["width"], spritesDict[name]["height"]) width = spritesDict[name]["width"] height = spritesDict[name]["height"] image = QImage() image.load(sprites + ".png") sprite = image.copy(rect) pngPath = os.path.join(os.path.dirname(sprites), name + ".png") sprite.save(pngPath) with open(pngPath, "rb") as f: data = f.read() base64 = data.encode("base64") svgPath = os.path.join(os.path.dirname(sprites), name + ".svg") with open(svgPath, "w") as f: f.write symbol = QgsMarkerSymbol() symbolLayer = QgsSvgMarkerSymbolLayer(svgPath) symbol.setSize(max([width, height])) symbol.appendSymbolLayer(symbolLayer) symbol.deleteSymbolLayer(0) return symbol