Skip to main content
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGISAccessing QGIS processing with PyQGIS

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

deleted 13 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

Thanks!

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

Thanks!

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

Source Link
dms
  • 41
  • 5

QGIS explode lines from python script fails at alg.processAlgorithm

I've been trying to run QGIS procedures from python scripts via terminal on Ubuntu (ultimately I want to automate a process via cron). The first task I have tried to script is the "explode lines" function. In particular, I have input QGIS with a roads shapefile that I hope to split into smaller segments.

I've been following several stackexchange links to get to where I am, but can't seem to get the last step to work. In the following bit of code, I get through the statement print("6") in the print statements, but fail correctly use alg.processAlgorithm(process). There is no error provided and the code seemingly exits.

#!/usr/bin/env python
import sys
from qgis.core import *
import qgis.utils
from qgis.gui import *     # QgsMapCanvas
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

# Prepare processing framework 
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
from processing.algs.Explode import *
from processing.core.SilentProgress import SilentProgress
progress = SilentProgress()

# Run the algorithm
print("1")
map = QgsMapCanvas()
print("2")
layerInput = QgsVectorLayer('/home/user/Downloads/input.shp', 'test', 'ogr')
print("3")
#map.setLayerSet([layerInput])
outLayer = '/home/user/out.shp'
print("4")
alg = Explode()
alg.setParameterValue('INPUT', layerInput)
print("5")
alg.setOutputValue('OUTPUT', outLayer)
print("6")
alg.processAlgorithm(progress)
print("7")
QgsApplication.exitQgis()
QApplication.exit()

Can anyone see what I've done incorrectly? I've been using the following link for help: Accessing QGIS processing with PyQGIS

Thanks!