1

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?

2

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.

  • 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. – user30184 Feb 23 '18 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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