Skip to main content
added 41 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Saving GPKGGeoPackage with style in PyQGIS

I have a function whothat uses a layer already styled using another function and saves it as a gpkg.gpkg and I want to save the style in that gpkg.gpkg:

def saving_gpkg(styled_layer):
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.driverName = "GPKG"
    QgsVectorFileWriter.writeAsVectorFormatV2(styled_layer, "nice_filename", QgsCoordinateTransformContext(), options)
    styled_layer.saveStyleToDatabase("polygon", "style automatically created", True, "")
def saving_gpkg(styled_layer):
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.driverName = "GPKG"
    QgsVectorFileWriter.writeAsVectorFormatV2(styled_layer, "nice_filename", QgsCoordinateTransformContext(), options)
    styled_layer.saveStyleToDatabase("polygon", "style automatically created", True, "")

The gpkg.gpkg is created, but if I open the created file, it doesn't have the defined style, just a random singlesymbolsingle symbol. I'm missing something?

Saving GPKG with style in PyQGIS

I have a function who uses a layer already styled using another function and saves it as a gpkg and I want to save the style in that gpkg:

def saving_gpkg(styled_layer):
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.driverName = "GPKG"
    QgsVectorFileWriter.writeAsVectorFormatV2(styled_layer, "nice_filename", QgsCoordinateTransformContext(), options)
    styled_layer.saveStyleToDatabase("polygon", "style automatically created", True, "")

The gpkg is created, but if I open the created file, it doesn't have the defined style, just a random singlesymbol. I'm missing something?

Saving GeoPackage with style in PyQGIS

I have a function that uses a layer already styled using another function and saves it as a .gpkg and I want to save the style in that .gpkg:

def saving_gpkg(styled_layer):
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.driverName = "GPKG"
    QgsVectorFileWriter.writeAsVectorFormatV2(styled_layer, "nice_filename", QgsCoordinateTransformContext(), options)
    styled_layer.saveStyleToDatabase("polygon", "style automatically created", True, "")

The .gpkg is created, but if I open the created file, it doesn't have the defined style, just a random single symbol. I'm missing something?

Tweeted twitter.com/StackGIS/status/1393899037162721281
Became Hot Network Question
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link
aldeano
  • 315
  • 1
  • 11

Saving GPKG with style in PyQGIS

I have a function who uses a layer already styled using another function and saves it as a gpkg and I want to save the style in that gpkg:

def saving_gpkg(styled_layer):
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.driverName = "GPKG"
    QgsVectorFileWriter.writeAsVectorFormatV2(styled_layer, "nice_filename", QgsCoordinateTransformContext(), options)
    styled_layer.saveStyleToDatabase("polygon", "style automatically created", True, "")

The gpkg is created, but if I open the created file, it doesn't have the defined style, just a random singlesymbol. I'm missing something?