I am trying to create a standalone script using the code below. I was able to add a shapefile with no errors but when I add map = QgsMapCanvas()
after qgs.initQgis()
and map.setLayerSet([QgsMapCanvasLayer(layer)])
after QgsMapLayerRegistry.instance().addMapLayer(layer)
I get the following errors: Cannot Create a QPixmap when no GUI is being used
and Cannot Create a Qwidget when no GUI is being used
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import iface
import sys, os
qgs = QgsApplication(sys.argv, False)
qgis_prefix = "C:\\OSGeo4W\\apps\\qgis"
QgsApplication.setPrefixPath(qgis_prefix, True)
qgs.initQgis()
map = QgsMapCanvas()
layer = QgsVectorLayer("F:/IrrigatedLands/FC_qgis/boundary.shp", "testlayer_shp", "ogr")
if not layer.isValid():
print "Layer failed to load!"
else:
print "Layer was loaded successfully!"
QgsMapLayerRegistry.instance().addMapLayer(layer)
map.setLayerSet([QgsMapCanvasLayer(layer)])
print layer