I have a code that takes a polygon layers and returns a temp point layer, I want to change the symbology for the point layer to the "topo pop capital" point symbol through Python.
fn = "C:/Users/Public/Desktop/OSGeo4W/bigBoi.shp"
layer = QgsVectorLayer (fn)
feats = layer.getFeatures()
vl = QgsVectorLayer("Point", "temp", "memory")
pr = vl.dataProvider()
for feat in feats:
geom =feat.geometry()
geomSingleType = QgsWkbTypes.isSingleType(geom.wkbType())
if geom.type() == QgsWkbTypes.PolygonGeometry:
if geomSingleType :
x = geom.asPolygon()
for i in x:
for y in i:
for q in y:
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(q))
pr.addFeature(f)
vl.updateExtents()
QgsProject.instance().addMapLayer(vl)
else:
x = geom.asMultiPolygon()
for i in x:
for y in i:
for q in y:
print(q)
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPointXY(q))
pr.addFeature(f)
vl.updateExtents()
QgsProject.instance().addMapLayer(vl)
I found the setSymbol fucntion that takes a symbol and renders it on a layer like so:
symbol = QgsMarkerSymbolV2.createSimple({'name': 'square', 'color': 'red'})
layer.rendererV2().setSymbol(symbol)
I also found that you can "copy symbol" by right clicking on an existing layer with the desired symbol, but that returns an HTML-like code which for some reason I can't paste here.
Is there a way to create the symbol with the copy symbol output as an object? Is the topo pop capital a symbol layer? And if so how do I appendSymbolLayer() if I don't know how to reference it. Can I call to the symbols from the single symbol favorites? Or maybe export the symbol to get it in Python template?