[QGIS-Developer] Error exporting to the geopackage file with layer style

Francisco Danubio Salas Rosette franksalas1965 at gmail.com
Mon Apr 6 17:19:39 PDT 2020


Hi List,
I need to export the layers to a geopackage file, which also includes the
style defined in the layer. I have been reviewing documentation but I have
not been able to perform this task, this is part of the code I am using.
With this code I manage to create the geopackage file but it does not
include the style of the layer


 def AddPostgisLayer_to_gpk(self):
        uri = QgsDataSourceUri()
        esquema = '25_hidrografia'
        loadlayer = 'embalses'
        GpName = r'd:\temp\embalses.gpkg'
        firstt = True
        options = QgsVectorFileWriter.SaveVectorOptions()
        uri.setConnection("localhost", "5432", "bdsapromat", "postgres",
"postgres", QgsDataSourceUri.SslDisable)

        uri.setDataSource(esquema, loadlayer, "geom", "geocodigo like " +
"'%-1'" )
        uri.setSrid("4326")
        vlayer = QgsVectorFileWriter(uri.uri(), loadlayer, "postgres")
        options.layerName = loadlayer+"_puntual"
        QgsVectorFileWriter.setSymbologyExport(vlayer,
QgsVectorFileWriter.SymbolLayerSymbology)
        _writer = QgsVectorFileWriter.writeAsVectorFormat(vlayer, GpName,
options)

Regards, Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200406/494ca49a/attachment.html>


More information about the QGIS-Developer mailing list