本文整理汇总了Python中qgis.core.QgsAuxiliaryStorage.save方法的典型用法代码示例。如果您正苦于以下问题:Python QgsAuxiliaryStorage.save方法的具体用法?Python QgsAuxiliaryStorage.save怎么用?Python QgsAuxiliaryStorage.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsAuxiliaryStorage
的用法示例。
在下文中一共展示了QgsAuxiliaryStorage.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCreateSaveOpenStorageWithString
# 需要导入模块: from qgis.core import QgsAuxiliaryStorage [as 别名]
# 或者: from qgis.core.QgsAuxiliaryStorage import save [as 别名]
def testCreateSaveOpenStorageWithString(self):
# Empty string in copy mode. A new database is created in a temporary
# file.
s0 = QgsAuxiliaryStorage()
self.assertTrue(s0.isValid())
# saveAs should be used instead of save in case of an empty string
# given to the constructor of QgsAuxiliaryStorage
self.assertEqual(s0.fileName(), "")
self.assertFalse(s0.save())
# Create a new auxiliary layer with 'pk' as key
vl0 = createLayer()
pkf = vl0.fields().field(vl0.fields().indexOf('pk'))
al0 = s0.createAuxiliaryLayer(pkf, vl0)
self.assertTrue(al0.isValid())
# Test the auxiliary key
key = al0.joinInfo().targetFieldName()
self.assertEqual(key, 'pk')
# Add a field in auxiliary layer
p = QgsPropertyDefinition('propName', QgsPropertyDefinition.DataTypeNumeric, '', '', 'user')
self.assertTrue(al0.addAuxiliaryField(p))
# saveAs without saving the auxiliary layer, the auxiliary field is lost
f = tmpPath()
self.assertTrue(s0.saveAs(f))
# Open the previous database.
s1 = QgsAuxiliaryStorage(f)
self.assertTrue(s1.isValid())
# Load the auxiliary layer from auxiliary storage
self.assertTrue(vl0.loadAuxiliaryLayer(s1, key))
# As the vl0 has not been saved before saving the storage, there
# shouldn't have auxiliary fields
self.assertEqual(len(vl0.auxiliaryLayer().auxiliaryFields()), 0)
# Save the layer before saving the storage
self.assertTrue(al0.save())
self.assertTrue(s0.saveAs(f))
# Open the previous database.
s2 = QgsAuxiliaryStorage(f)
self.assertTrue(s2.isValid())
# Load the auxiliary layer from auxiliary storage
self.assertTrue(vl0.loadAuxiliaryLayer(s2, key))
# As the vl0 has been saved before saving the storage, there
# should have 1 auxiliary field
self.assertEqual(len(vl0.auxiliaryLayer().auxiliaryFields()), 1)
# save is available on s2
self.assertTrue(s2.save())
示例2: testCreateSaveOpenStorageWithProject
# 需要导入模块: from qgis.core import QgsAuxiliaryStorage [as 别名]
# 或者: from qgis.core.QgsAuxiliaryStorage import save [as 别名]
def testCreateSaveOpenStorageWithProject(self):
# New project without fileName
p = QgsProject()
# Create storage
s0 = QgsAuxiliaryStorage(p)
self.assertTrue(s0.isValid())
# saveAs should be used instead of save in case of an empty string
# given to the constructor of QgsAuxiliaryStorage
self.assertEqual(s0.fileName(), "")
self.assertFalse(s0.save())
# saveAs
f = tmpPath()
self.assertTrue(s0.saveAs(f))