Skip to main content
edited body
Source Link

I think I got it, but if anyone has a better solution.

path = r"C:\Users\Aloísio\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\QWater\icons\qwater.svg"
layerName = 'rede_bombas'
vLayer = QgsProject.instance().mapLayersByName(layerName)[0]

symbol_svg = QgsSvgMarkerSymbolLayer(path)
symbol_svg.setSize(6)
symbol_svg.setFillColor(QColor('#0000ff'))
symbol_svg.setStrokeColor(QColor('#ff0000'))
symbol_svg.setStrokeWidth(1)

marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, symbol_svg)

ggsl = QgsGeometryGeneratorSymbolLayer.create({})
ggsl.setSubSymbol(marker_symbol)
ggsl.setGeometryExpression("centroid($geometry)")

symbol = vLayer.renderer().symbols(QgsRenderContext())[0]
symbol.insertSymbolLayer(1, ggsl)
vLayer.triggerRepaint()

enter image description hereenter image description here

I think I got it, but if anyone has a better solution.

path = r"C:\Users\Aloísio\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\QWater\icons\qwater.svg"
layerName = 'rede_bombas'
vLayer = QgsProject.instance().mapLayersByName(layerName)[0]

symbol_svg = QgsSvgMarkerSymbolLayer(path)
symbol_svg.setSize(6)
symbol_svg.setFillColor(QColor('#0000ff'))
symbol_svg.setStrokeColor(QColor('#ff0000'))
symbol_svg.setStrokeWidth(1)

marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, symbol_svg)

ggsl = QgsGeometryGeneratorSymbolLayer.create({})
ggsl.setSubSymbol(marker_symbol)
ggsl.setGeometryExpression("centroid($geometry)")

symbol = vLayer.renderer().symbols(QgsRenderContext())[0]
symbol.insertSymbolLayer(1, ggsl)
vLayer.triggerRepaint()

enter image description here

I think I got it, but if anyone has a better solution.

path = r"C:\Users\Aloísio\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\QWater\icons\qwater.svg"
layerName = 'rede_bombas'
vLayer = QgsProject.instance().mapLayersByName(layerName)[0]

symbol_svg = QgsSvgMarkerSymbolLayer(path)
symbol_svg.setSize(6)
symbol_svg.setFillColor(QColor('#0000ff'))
symbol_svg.setStrokeColor(QColor('#ff0000'))
symbol_svg.setStrokeWidth(1)

marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, symbol_svg)

ggsl = QgsGeometryGeneratorSymbolLayer.create({})
ggsl.setSubSymbol(marker_symbol)
ggsl.setGeometryExpression("centroid($geometry)")

symbol = vLayer.renderer().symbols(QgsRenderContext())[0]
symbol.insertSymbolLayer(1, ggsl)
vLayer.triggerRepaint()

enter image description here

Source Link

I think I got it, but if anyone has a better solution.

path = r"C:\Users\Aloísio\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\QWater\icons\qwater.svg"
layerName = 'rede_bombas'
vLayer = QgsProject.instance().mapLayersByName(layerName)[0]

symbol_svg = QgsSvgMarkerSymbolLayer(path)
symbol_svg.setSize(6)
symbol_svg.setFillColor(QColor('#0000ff'))
symbol_svg.setStrokeColor(QColor('#ff0000'))
symbol_svg.setStrokeWidth(1)

marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, symbol_svg)

ggsl = QgsGeometryGeneratorSymbolLayer.create({})
ggsl.setSubSymbol(marker_symbol)
ggsl.setGeometryExpression("centroid($geometry)")

symbol = vLayer.renderer().symbols(QgsRenderContext())[0]
symbol.insertSymbolLayer(1, ggsl)
vLayer.triggerRepaint()

enter image description here