我有一个在 QGIS 的 python 控制台中工作的代码。我正在尝试在 IDE 中工作,但它不起作用。我以不同的方式更改了它,但它仍然返回:
QPixmap: Must construct a QApplication before a QPaintDevice
我的代码是:
import processing
from qgis.core import*
from PyQt4.QtCore import *
import math
from collections import defaultdict
from shapely.geometry import LineString
import json
import datetime
import time
import itertools
import glob
import sys
from nltk import metrics
Class matching():
def __init__(self):
self.layers = []
self.Dir_OSM_roads="D:/PhD works/PhD things/Julian/Matching_data/InputData/SHP/OSM_roads_no_psv_latin1_id.shp"
def laodLayer(self):
self.layers[0]=QgsVectorLayer(self.Dir_OSM_roads,"test" , "ogr")
QgsMapLayerRegistry.instance().addMapLayer(self.layers[0]);
print self.layers[0]
def printValidity(self):
if not self.layers[0].isValid():
print "layer does not exist"
else:
print "successful"
def main():
app = QApplication([],True)
qgis_prefix = "C:/Program Files (x86)/QGIS Valmiera/apps/qgis"
QgsApplication.setPrefixPath(qgis_prefix, True)
QgsApplication.initQgis()
check=matching()
check.laodLayer()
check.printValidity()
retval = app.exec_()
QgsApplication.exitQgis()
sys.exit(retval)
if __name__ == '__main__':
main()
我正在使用 aptana 和 QGIS 2.2 在 Windows 7、64 中工作。
编辑:我的窗户是 64 位的