Running PyQGIS script in Windows

المشرف العام

Administrator
طاقم الإدارة
I'm not able to run the following PyQGIS script in Windows (it worked perfectly in OS X):

import sysimport osfrom qgis.core import *import qgis.utilsfrom qgis.analysis import *app = QgsApplication([],True,"")# supply path to where is your qgis installedQgsApplication.setPrefixPath(os.getenv("QGISPATH"), True)# load providersQgsApplication.initQgis()sys.path.append(os.getenv("QGISPATH")+"/apps/qgis/python/plugins")import processing# Load layers with precincts and zip codesprint os.path.exists("../external/precincts/USA_precincts.shp")layer1 = QgsVectorLayer("../external/precincts/USA_precincts.shp", "precincts", "ogr")if layer1.isValid(): print "Loaded layer 1"else: print "Layer 1 failed to load!"layer2 = QgsVectorLayer("../external/zipcodes/Bnd_2008_q3_region.shp", "zipcodes", "ogr")if layer2.isValid(): print "Loaded layer 2"else: print "Layer 2 failed to load!"# Spatial intersection between layers, save it as a new shapefileoverlayAnalyzer = QgsOverlayAnalyzer() overlayAnalyzer.intersection(layer1, layer2, "../temp/precinctsZipcodes.shp")QgsApplication.exitQgis()The initial lines run fine, but then the code is not able to load the shapefiles. The output from the line print os.path.exists("../external/precincts/USA_precincts.shp") is True, but then it prints Layer 1 failed to load! when checking whether the layer was loaded correctly.

Does anyone know why it does not run in Windows? I was even able to run it in the python console (only running the lines between layer1 = QgsVectorLayer ... and the second to last line).



أكثر...
 
أعلى