我正在使用PyQGIS Cookbook学习PyQGIS,并购买了PyQGIS Programmers Guide。我已经能够使用小脚本加载图层,但没有运气将项目加载到QGIS中。我一直得到一个' SyntaxError:无效的语法'对于第13行。我在QGIS中使用Python控制台并输入' import _loadproject'启动脚本。
有人可以指出我哪里出错吗?
"""Load Project: This is to test loading a project."""
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface
class ProjectScript:
def __init__(self, iface):
self.iface = iface
def load_project(self)
project = QgsProject.instance() \
project.read(QFileInfo('S:/SOCAL/Section_28/SOCAL_CK47/Control_Data/SOCAL_CK47_project.qgs'))
print project.fileName 'S:/SOCAL/Section_28/SOCAL_CK47/Control_Data/SOCAL_CK47_project.qgs'
def run_script(iface):
"""Run the script by loading and calling LoadProject methods."""
fs = ProjectScript(iface)
fs.load_project()
答案 0 :(得分:1)
检查此示例:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface
class ProjectScript:
def __init__(self, iface):
self.iface = iface
def load_project(self):
project = QgsProject.instance()
project.read(QFileInfo('S:\\SOCAL\\Section_28\\SOCAL_CK47\\Control_Data\\SOCAL_CK47_project.qgs'))
print project.fileName()
def run_script(iface):
"""Run the script by loading and calling LoadProject methods."""
fs = ProjectScript(iface)
fs.load_project()