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.
C:/someDirectory/files/centre/colour/streets.shp
. What happens if you typeprint layerInput
?general.runalg('qgis:explodelines', 'C:/someDirectory/files/centre/colour/streets.shp', 'temp.shp')