[Qgis-user] Issues by using a script inside the python console
Hesels, Marie-Christine
marie.hesels at rwth-aachen.de
Tue Sep 13 23:11:33 PDT 2022
Hi Richard,
thanks for your hint! By adding the QgsProcessingFeatureSourceDefinition, it works :)
Regards,
Marie
________________________________
Von: Richard Duivenvoorde <rdmailings at duif.net>
Gesendet: Dienstag, 13. September 2022 20:46:59
An: Hesels, Marie-Christine; qgis-user at lists.osgeo.org
Betreff: Re: [Qgis-user] Issues by using a script inside the python console
I use succesfully the following in a script and a plugin:
# Voronoing ONLY the selected
# NOTE: the colon (:) behind 'memory' in the 'OUTPUT' param is mandatory,
# else QGIS will create a geopackage!
selected = True
params = {
'INPUT': QgsProcessingFeatureSourceDefinition(point_layer.id(), selectedFeaturesOnly=selected),
'OUTPUT': 'memory:',
'BUFFER': 5,
}
result = processing.run("qgis:voronoipolygons", params)
Maybe you can use that to reconstruct your call?
Regards,
Richard Duivenvoorde
On 9/13/22 10:52, Hesels, Marie-Christine via Qgis-user wrote:
> Hi all,
>
>
> I am currently using the "Snap to Roads" script inside my qgis environment, to match gpx-points to the OSM (https://spatialthoughts.com/2020/02/22/snap-to-roads-qgis-and-osrm/ <https://spatialthoughts.com/2020/02/22/snap-to-roads-qgis-and-osrm/>).
>
> I am able to execute the Script by using the QGIS Script Environment:
>
>
>
> Unfortunatly, I would like to run the script via python console inside QGiS, but this doesn't work at all ...
>
>
> By executing the following command:
>
>
> layer_SnappedLine = processing.run("script:snap_to_roads",
> {'INPUT':layer_GPX_Points['OUTPUT'],
> 'SERVICE':'http://127.0.0.1:5000',
> 'TOLERANCE':10,
> 'OUTPUT':'TEMPORARY_OUTPUT'})
>
> I receive the error message:
>
> "Traceback (most recent call last):
>
> File "C:\PROGRA~1\QGIS32~1.10\apps\Python39\lib\code.py", line 90, in runcode
> exec(code, self.locals)
> File "<input>", line 1, in <module>
> File "C:\PROGRA~1/QGIS32~1.10/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 108, in run
> return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
> File "C:\PROGRA~1/QGIS32~1.10/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 205, in runAlgorithm
> layer = context.takeResultLayer(result) # transfer layer ownership out of context
> TypeError: QgsProcessingContext.takeResultLayer(): argument 1 has unexpected type 'QgsFeatureSink'"
>
> Can anybody help me with this issue? I am using QGIS Version 3.22.10
>
> Regards and thanks,
> Marie
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220914/2fcff7cf/attachment.htm>
More information about the Qgis-user
mailing list