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,136
  • 29
  • 109
  • 338

0 Answers0