[Qgis-user] Convert symbology of qgis layer into PyQGIS code to define renderer
Jorge Gustavo Rocha
jgr at geomaster.pt
Fri Jun 11 06:41:35 PDT 2021
Olá Manuel,
There is no way to get the PyQGIS code from the style, as far as I know.
But you can save the style (using the native QGIS format) and apply the
named style afterwards in PyQGIS easily. Is this alternative workflow
suitable for you?
Regards,
Gustavo
On 11/06/21 12:56, Manuel Campagnolo wrote:
> Hi
>
> Do you know of a way of using the style of a ,say, vector layer in
> QGIS3 to create automatically the python code that would generate it,
> namely the QgsSymbol part in the code below.
>
> Thanks
>
>
> symbol1=QgsSymbol.defaultSymbol(ifn_ppsm.geometryType())
> symbol2=QgsSymbol.defaultSymbol(ifn_ppsm.geometryType())
> symbol3=QgsSymbol.defaultSymbol(ifn_ppsm.geometryType())
> symbol4=QgsSymbol.defaultSymbol(ifn_ppsm.geometryType())
> symbol5=QgsSymbol.defaultSymbol(ifn_ppsm.geometryType())
>
> symbol1.setColor(QColor('black'))
> symbol2.setColor(QColor('gray'))
> symbol3.setColor(QColor('dark green'))
> symbol4.setColor(QColor('light green'))
> symbol5.setColor(QColor('orange'))
>
> cat1=QgsRendererCategory('Improdutivos', symbol1, 'Improdutivos') #
> category, symbol, label
> cat2=QgsRendererCategory('Urbano', symbol2, 'Urbano')
> cat3=QgsRendererCategory('Matos e Pastagens', symbol3, 'Matos e
> Pastagens')
> cat4=QgsRendererCategory('Floresta', symbol4, 'Floresta')
> cat5=QgsRendererCategory('Agricultura', symbol5, 'Agricultura')
> categories=[cat1,cat2,cat3,cat4,cat5] # list
>
> renderer = QgsCategorizedSymbolRenderer('usosolo', categories)
> ifn_ppsm.setRenderer(renderer)
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
More information about the Qgis-user
mailing list