0

I can create a new geopackage and write a tmp layer to it using code below:

#Create a layer
lyr = processing.run("native:randompointsinextent", {'EXTENT':'376242.90699403384,385761.27711294894,6245699.079987993,6249398.011089481 [EPSG:3006]','POINTS_NUMBER':10,'MIN_DISTANCE':0,'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:3006'),'MAX_ATTEMPTS':200,'OUTPUT':'TEMPORARY_OUTPUT'})['OUTPUT']

newgpkg = r'C:\GIS\data\testdata\newgpkg.gpkg'
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "gpkg"

QgsVectorFileWriter.writeAsVectorFormatV2(lyr, newgpkg, QgsCoordinateTransformContext(), options)

But how can I name the table? Here both the geopackage and the layer is named newgpkg.

(This is just a workaround to create a new geopackage and table using code. So if there is another way of doing that, please let me know)

0

1 Answer 1

3

You should add the following

options.layerName = 'your_wanted_name'

Found by looking at QgsVectorFileWriter::SaveVectorOptions (C++ doc)

Not the answer you're looking for? Browse other questions tagged or ask your own question.