[QGIS-Developer] [Info][Howto] Python Processing script to create an output without input

João Gaspar joao.f.r.gaspar at gmail.com
Thu Aug 1 01:48:05 PDT 2019


Hi Nyall,
sorry for the iface issue my bad. When I used it was to attempt to load the
layer after the creation of the vector layer.

1 lesson learn - Hey iface stay away from processing :P

Thank you for your time this small fix is now working.

Best regards.

Nyall Dawson <nyall.dawson at gmail.com> escreveu no dia quarta, 31/07/2019
à(s) 23:45:

> On Thu, 1 Aug 2019 at 01:30, João Gaspar <joao.f.r.gaspar at gmail.com>
> wrote:
> >
> > Hi devs
> > I'm trying to do a Python Script in Processing without an input layer
> and generate an output layer based on a number of fields that respects an
> order, name, type of field, precision.
> >
> > The problem: I have some standard procedures that use a template
> shapefile. Most of the time users create a new template or truncate
> existing layers.
> >
> > To save some clicks what I'm trying to do is create instantly the
> templates without user lose time. I'm using processing to get the advantage
> of batch mode.
> >
> > This is my actual code but crashes when I run (see .py in attach)
> >
> > I think the problem is in the moment of writing the output file.
>
> Ouch - never, EVER use "iface" in Processing scripts!
>
> The problem is in the line:
>
> layer = iface.addVectorLayer(self.OUTPUT, 'layer1', 'ogr')
>
> You should remove this line, and replace the return dict with the path
> to your created layer, e.g.:
>
> return {self.OUTPUT: '/home/me/my.shp'}
>
> Processing will automatically load this as a layer when required.
>
> Nyall
>
>
>
> >
> > Kind regards
> >
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190801/d058f182/attachment-0001.html>


More information about the QGIS-Developer mailing list