[Qgis-user] Pygis path or field index from layer ID
Sebastian Gutwein
bas at rdgland.com
Wed Nov 18 08:01:32 PST 2020
Hi,
I am trying to create a tool that chains together some algorithms.
Normally I would just use the graphical modeler but one of the tools I want
to chain together is Tin Interpolation that doesn't seem to work well with
the modeler.
I have gotten it to work by setting up what I can in the modeler and then
exporting and modifying a python script.
One thing that I can't seem to get to work is the input field for the
interpolation plugin. It appears to need the field index.
I can get the field index if I have the file path but when I use the Vector
Layer Parameter like this:
*self.addParameter(QgsProcessingParameterVectorLayer('Elevationpoints',
'Elevation_points', types=[QgsProcessing.TypeVectorAnyGeometry],
defaultValue=None))*
This seems to return the layer ID rather than the path. Something like this:
*'Elevationpoints_ad0ce945_8f93_4e0e_8fe7_5b053ef287dd'*
In the console I get the correct result if I run script this with the path-
*vlayer = QgsVectorLayer('C:\Elevationpoints.shp')index =
vlayer.fields().lookupField('Lidar')print(index)*
But if I try to use the layer ID from the console or the script GUI I get
-1 meaning the field was not found.
And if I run dataprovider() it says the layer doesn't have a data provider.
How can I get the field index from the layer ID?
I also posted this question on stack exchange.
https://gis.stackexchange.com/questions/379502/index-of-field-layer-where-i-have-the-layer-id-pyqgis-3
Thanks for the help!
-Bas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20201118/f7cc368c/attachment.html>
More information about the Qgis-user
mailing list