1

I want to access the explodelines function in Python outside of QGIS from a standalone script.

import sip
for api in ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]:
    sip.setapi(api, 2)


import sys
from qgis.core import *
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("C:/OSGeo4W64/apps/qgis", True)
QgsApplication.initQgis()

# Prepare processing framework
sys.path.append('C:/OSGeo4W64/apps/qgis/python/plugins')

from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *

# Run the algorithm
layerInput = QgsVectorLayer("files/centre/colour/streets.shp", 'test', 'ogr')
general.runalg('qgis:explodelines', layerInput, 'temp.shp')

# Exit applications
QgsApplication.exitQgis()
QApplication.exit()

EDIT:

The result of the algorithm is: 'NoneType' object has no attribute 'error' I used various shapefiles but none of them worked.

8
  • 1
    Did you try using the full path to the shapefile? (e.g. C:/someDirectory/files/centre/colour/streets.shp. What happens if you type print layerInput?
    – Joseph
    Commented Jan 23, 2018 at 12:31
  • Yes, I tried, but no change. <qgis._core.QgsVectorLayer object at 0x00000000144D68C8> Commented Jan 23, 2018 at 12:33
  • Sorry, I meant using the full path as the input parameter: general.runalg('qgis:explodelines', 'C:/someDirectory/files/centre/colour/streets.shp', 'temp.shp')
    – Joseph
    Commented Jan 23, 2018 at 12:55
  • No, it don't change anything.. The error: 'NoneType' object has no attribute 'error' appears Commented Jan 23, 2018 at 13:09
  • There could be errors in your shapefile. Try loading the shapefile into QGIS and running the Check validity tool.
    – Joseph
    Commented Jan 23, 2018 at 13:32

1 Answer 1

1

On the following link the problem with the processing framework has been solved: Link 1

--> Just change two lines in AlgorithmExecutor.py like this.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.