Thursday, 6 December 2018

pyqgis - Segmentation Fault upon exit of QGIS map canvas


I have simplified my original code. My code is very similar to Pyqgis' cookbook. I am simply loading one VALID layer to QgsMapCanvas and then displaying it. Everything is displayed corectly etc. Problem is, everytime I exit out of the QgsMapCanvas GUI, my code then shows a segmentation fault (core dumped) message. How can I prevent this from happening?


from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *


def main():

# initiate canvas for debugging purposes
# supply path to qgis install location
QgsApplication.setPrefixPath('/usr', True)
# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
app = QgsApplication([], True)
# load providers
app.initQgis()

# create Qt mapCanvas object

canvas = QgsMapCanvas()
canvas.setCanvasColor(Qt.transparent)
# enable this for smooth rendering
canvas.enableAntiAliasing(True)

# create vector layer object
layer = QgsVectorLayer('BUAARE.shp', 'layer', 'ogr')

if layer.isValid():
QgsMapLayerRegistry.instance().addMapLayer(layer)

canvas.setExtent(layer.extent())
canvas.setLayerSet([QgsMapCanvasLayer(layer)])

canvas.show()
app.exec_()

# exit qgis
app.exitQgis()
main()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...