QGIS-2.8-PyQGISDeveloperCookbook-en(9)
时间:2025-03-11
时间:2025-03-11
为开发人员准备的文档,涵盖QGIS的多种功能实现和代码。
CHAPTER2
LoadingProjects
Sometimesyouneedtoloadanexistingprojectfromapluginor(moreoften)whendevelopingastand-alone
QGISPythonapplication(see:PythonApplications).
ToloadaprojectintothecurrentQGISaplicationyouneedaQgsProjectinstance()objectandcallits
read()methodpassingtoitaQFileInfoobjectthatcontainsthepathfromwheretheprojectwillbeloaded:
Incaseyouneedtomakesomemodi cationstotheproject(forexampleaddorremovesomelayers)andsave
yourchanges,youcancallthewrite()methodofyourprojectinstance.Thewrite()methodalsoacceptsan
optionalQFileInfothatallowsyoutospecifyapathwheretheprojectwillbesaved:
Bothread()andwrite()funtionsreturnabooleanvaluethatyoucanusetocheckiftheoperationwas
successful.