예, 방법이 있습니다. 그러나 지금까지 내가 찾은 것은 전체 Qgis 라이브러리를 최종 소프트웨어 패키지에 복사해야한다는 것입니다.
QgsApplication.setPrefixPath(r"C:\OSGeo4W\apps\qgis", True)
QgsApplication.initQgis()
QgsProject.instance().setFileName(strProjectName)
는 또한 우리가 파일을 작성하고 최종
QgsProject.instance().write()
QgsApplication.exitQgis()
에 닫을 필요가 여기에 스탠드의 스냅 샷입니다 : 다음과 같이 코드 내부 QGIS 응용 프로그램에 대한 올바른 경로를 설정하는 것이 매우 중요합니다 혼자서 만든 패키지입니다. 일부 변수가 작동하려면 코드를 수정해야합니다.
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import os, datetime
class CreateQgs():
def initQgsFile(self, outputFolder, stopRadius):
strProjectName = str(outputFolder) + "\\" + "PhotoLocationMap.qgs"
QgsApplication.setPrefixPath(r"C:\OSGeo4W\apps\qgis", True)
QgsApplication.initQgis()
QgsProject.instance().setFileName(strProjectName)
highwayShapeFilePath = "C:/Shapefiles/Highway.shp"
arterialShapeFilePath = "C:/Shapefiles/StreetsMajor.shp"
highwayLayer = QgsVectorLayer(self.highwayShapeFilePath, 'HighwayDB' , 'ogr')
arterialLayer = QgsVectorLayer(self.arterialShapeFilePath, 'ArterialDB', 'ogr')
symbols = highwayLayer.rendererV2().symbols()
sym = symbols[0]
sym.setColor(QColor.fromRgb(255,94,94))
highwayLayer.triggerRepaint()
symbols = arterialLayer.rendererV2().symbols()
sym = symbols[0]
sym.setColor(QColor.fromRgb(76,138,245))
arterialLayer.triggerRepaint()
mapInstance = QgsMapLayerRegistry.instance()
mapInstance.instance().addMapLayer(arterialLayer)
mapInstance.instance().addMapLayer(highwayLayer)
QgsProject.instance().write()
QgsApplication.exitQgis()
def unitTest():
app = QgsApplication(sys.argv, True)
photoFolderPath = 'C:\Test\QGis\TestPics'
CreateQgsFile = CreateQgs()
CreateQgsFile.initQgsFile(photoFolderPath, 128)
if __name__ == "__main__":
unitTest()