2

Trying using the processing toolbox in a standalone python script the needed Algorithm could not be found:

Error: Algorithm not found 
Error in sys.excepthook:
Traceback (most recent call last):
 File "/Applications/QGIS.app/Contents/Resources/python/qgis/utils.py", line 196, in qgis_excepthook
 showException(type, value, tb, None, messagebar=True)
 File "/Applications/QGIS.app/Contents/Resources/python/qgis/utils.py", line 107, in showException
 open_stack_dialog(type, value, tb, msg)
 File "/Applications/QGIS.app/Contents/Resources/python/qgis/utils.py", line 142, in open_stack_dialog
 iface.messageBar().popWidget()
AttributeError: 'NoneType' object has no attribute 'messageBar' 
Original exception was:
Traceback (most recent call last):
 File "test_standalone_copy.py", line 33, in <module>
 outputs_QGISINTERSECTION_1=processing.runalg('qgis:intersection', outputs_QGISFIELDCALCULATOR_1['OUTPUT_LAYER'],polygon,False,None)
TypeError: 'NoneType' object has no attribute '__getitem__'

I tried already the solution in Error: Algorithm not found (QGIS) but unfortunately it didn't worked...

This is my script

import sys
sys.path.append('/Applications/QGIS.app/Contents/Resources/python')
sys.path.append('/Applications/QGIS.app/Contents/Resources/python/plugins')
sys.path.append('/Applications/QGIS.app/Contents/Resources/python/plugins/processing') 
import qgis
from qgis.core import * 
import json, requests
import processing 
# supply path to qgis install location
QgsApplication.setPrefixPath(r"/Applications/QGIS.app/Contents/MacOS", False)
# create a reference to the QgsApplication, setting the # second argument to False disables the GUI
qgs = QgsApplication([], False)
# load providers
qgs.initQgis() 
# test set of coordinates
geometry_decode = [(-0.125037,51.5307), (-0.12763,51.5338), (-0.128062,51.5344), (-0.128236,51.5346), (-0.128305,51.5347), (-0.128377,51.5348), (-0.128438,51.5349)]
geometry = [QgsPoint(point[1],point[0]) for point in geometry_decode] 
line = QgsGeometry.fromPolyline(geometry) 
route = QgsVectorLayer("LineString?crs=epsg:4326&index=yes","route","memory")
pr = route.dataProvider() 
route.startEditing() 
feature = QgsFeature()
feature.setGeometry(line) 
route.addFeatures([feature])
route.commitChanges()
QgsMapLayerRegistry.instance().addMapLayer(route) 
filepath_polygon ='ne_50m_admin_0_sovereignty.shp'
polygon = QgsVectorLayer(filepath_polygon,"countries","ogr") 
outputs_QGISFIELDCALCULATOR_1=processing.runalg('qgis:fieldcalculator',route,'tot_length',0,10.0,3.0,True,'$length',None)
outputs_QGISINTERSECTION_1=processing.runalg('qgis:intersection', outputs_QGISFIELDCALCULATOR_1['OUTPUT_LAYER'],polygon,False,None) 
# Write your code here to load some layers, use processing algorithms, etc.
# When your script is complete, call exitQgis() to remove the provider and # layer registries from memory
qgs.exitQgis()
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 28, 2018 at 13:47
2
  • Which QGIS version are you using? Commented Jan 29, 2018 at 11:10
  • Version 2.18.15 - Vienna Commented Jan 29, 2018 at 20:36

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.