本文整理汇总了Python中qgis.core.QgsProject.fileName方法的典型用法代码示例。如果您正苦于以下问题:Python QgsProject.fileName方法的具体用法?Python QgsProject.fileName怎么用?Python QgsProject.fileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsProject
的用法示例。
在下文中一共展示了QgsProject.fileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zip_unzip
# 需要导入模块: from qgis.core import QgsProject [as 别名]
# 或者: from qgis.core.QgsProject import fileName [as 别名]
def test_zip_unzip(self):
tmpDir = QTemporaryDir()
tmpFile = "{}/project.qgz".format(tmpDir.path())
project = QgsProject()
l0 = QgsVectorLayer(os.path.join(TEST_DATA_DIR, "points.shp"), "points", "ogr")
l1 = QgsVectorLayer(os.path.join(TEST_DATA_DIR, "lines.shp"), "lines", "ogr")
project.addMapLayers([l0, l1])
self.assertTrue(project.write(tmpFile))
project2 = QgsProject()
self.assertFalse(project2.isZipped())
self.assertTrue(project2.fileName() == "")
self.assertTrue(project2.read(tmpFile))
self.assertTrue(project2.isZipped())
self.assertTrue(project2.fileName() == tmpFile)
layers = project2.mapLayers()
self.assertEqual(len(layers.keys()), 2)
self.assertTrue(layers[l0.id()].isValid(), True)
self.assertTrue(layers[l1.id()].isValid(), True)
project2.clear()
self.assertFalse(project2.isZipped())
示例2: test_configpath
# 需要导入模块: from qgis.core import QgsProject [as 别名]
# 或者: from qgis.core.QgsProject import fileName [as 别名]
def test_configpath(self):
""" Test plugin can read confif path
"""
try:
from qgis.server import QgsServerFilter
from qgis.core import QgsProject
except ImportError:
print("QGIS Server plugins are not compiled. Skipping test")
return
d = unitTestDataPath('qgis_server_accesscontrol') + '/'
self.projectPath = os.path.join(d, "project.qgs")
self.server = QgsServer()
# global to be modified inside plugin filters
globals()['configFilePath2'] = None
class Filter0(QgsServerFilter):
"""Body setter, clear body, keep headers"""
def requestReady(self):
global configFilePath2
configFilePath2 = self.serverInterface().configFilePath()
serverIface = self.server.serverInterface()
serverIface.registerFilter(Filter0(serverIface), 100)
# Test using MAP
self._execute_request('?service=simple&MAP=%s' % self.projectPath)
# Check config file path
self.assertEqual(configFilePath2, self.projectPath)
# Reset result
globals()['configFilePath2'] = None
# Test with prqject as argument
project = QgsProject()
project.read(self.projectPath)
self._execute_request_project('?service=simple', project=project)
# Check config file path
self.assertEqual(configFilePath2, project.fileName())