2

I try to use qgis:creategrid processing tool. I want to give as output source gpkg layer which I have already create by defining it shape type, crs. However it does not work for me now. Here is my code:

parameters = {'TYPE': 2,
              'EXTENT': '%f,%f,%f,%f' % (xmin, xmax, ymin, ymax),
              'HSPACING': dx,
              'VSPACING': dy,
              'HOVERLAY': 0.0,
              'VOVERLAY': 0.0,
              'CRS': str(epsg),
              'OUTPUT': self.gpkgFile + "|layername=Grid_1"}

processing.run('qgis:creategrid', parameters)

self.gpkgFile is defined the gpkg source such as: D:\newProject\project1.gpkg

So 'OUTPUT' describes here: D:\newProject\project1.gpkg|layername=Grid_1

How can I use gpkg layer as 'OUTPUT'in such kind of processing tools?

1 Answer 1

6

Try specifying the output string as a full layer Uri, E.g.

"ogr:dbname='d:/package.gpkg' table=\"mylayer\" (geom) sql="

The easiest way to determine a valid string is to run the algorithm from the toolbox and then check the history panel - it will include all the parameter values including the output strings, so you could then copy and adapt those.

1
  • If you want to add a new layer into an existing gpkg database be aware to open it in update mode, otherwise the old gpkg data file will be overwritten. Ogr2ogr is using the -update switch for that by I do not know how to do that with pyqgis. Commented Feb 23, 2018 at 9:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.