本文整理汇总了Python中qgis.core.QgsProject.writeEntryBool方法的典型用法代码示例。如果您正苦于以下问题:Python QgsProject.writeEntryBool方法的具体用法?Python QgsProject.writeEntryBool怎么用?Python QgsProject.writeEntryBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsProject
的用法示例。
在下文中一共展示了QgsProject.writeEntryBool方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRelativePaths
# 需要导入模块: from qgis.core import QgsProject [as 别名]
# 或者: from qgis.core.QgsProject import writeEntryBool [as 别名]
def testRelativePaths(self):
"""
Test whether paths to layer sources are stored as relative to the project path
"""
tmpDir = QTemporaryDir()
tmpFile = "{}/project.qgs".format(tmpDir.path())
copyfile(os.path.join(TEST_DATA_DIR, "points.shp"), os.path.join(tmpDir.path(), "points.shp"))
copyfile(os.path.join(TEST_DATA_DIR, "points.dbf"), os.path.join(tmpDir.path(), "points.dbf"))
copyfile(os.path.join(TEST_DATA_DIR, "points.shx"), os.path.join(tmpDir.path(), "points.shx"))
copyfile(os.path.join(TEST_DATA_DIR, "lines.shp"), os.path.join(tmpDir.path(), "lines.shp"))
copyfile(os.path.join(TEST_DATA_DIR, "lines.dbf"), os.path.join(tmpDir.path(), "lines.dbf"))
copyfile(os.path.join(TEST_DATA_DIR, "lines.shx"), os.path.join(tmpDir.path(), "lines.shx"))
copyfile(os.path.join(TEST_DATA_DIR, "landsat_4326.tif"), os.path.join(tmpDir.path(), "landsat_4326.tif"))
project = QgsProject()
l0 = QgsVectorLayer(os.path.join(tmpDir.path(), "points.shp"), "points", "ogr")
l1 = QgsVectorLayer(os.path.join(tmpDir.path(), "lines.shp"), "lines", "ogr")
l2 = QgsRasterLayer(os.path.join(tmpDir.path(), "landsat_4326.tif"), "landsat", "gdal")
self.assertTrue(l0.isValid())
self.assertTrue(l1.isValid())
self.assertTrue(l2.isValid())
self.assertTrue(project.addMapLayers([l0, l1, l2]))
self.assertTrue(project.write(tmpFile))
del project
with open(tmpFile, 'r') as f:
content = ''.join(f.readlines())
self.assertTrue('source="./lines.shp"' in content)
self.assertTrue('source="./points.shp"' in content)
self.assertTrue('source="./landsat_4326.tif"' in content)
# Re-read the project and store absolute
project = QgsProject()
self.assertTrue(project.read(tmpFile))
store = project.layerStore()
self.assertEquals(set([l.name() for l in store.mapLayers().values()]), set(['lines', 'landsat', 'points']))
project.writeEntryBool('Paths', '/Absolute', True)
tmpFile2 = "{}/project2.qgs".format(tmpDir.path())
self.assertTrue(project.write(tmpFile2))
with open(tmpFile2, 'r') as f:
content = ''.join(f.readlines())
self.assertTrue('source="{}/lines.shp"'.format(tmpDir.path()) in content)
self.assertTrue('source="{}/points.shp"'.format(tmpDir.path()) in content)
self.assertTrue('source="{}/landsat_4326.tif"'.format(tmpDir.path()) in content)
del project