当前位置: 首页>>代码示例>>Python>>正文


Python core.QgsAuxiliaryStorage类代码示例

本文整理汇总了Python中qgis.core.QgsAuxiliaryStorage的典型用法代码示例。如果您正苦于以下问题:Python QgsAuxiliaryStorage类的具体用法?Python QgsAuxiliaryStorage怎么用?Python QgsAuxiliaryStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QgsAuxiliaryStorage类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testClear

    def testClear(self):
        s = QgsAuxiliaryStorage()
        self.assertTrue(s.isValid())

        # Create a new auxiliary layer with 'pk' as key
        vl = createLayer()
        pkf = vl.fields().field(vl.fields().indexOf('pk'))
        al = s.createAuxiliaryLayer(pkf, vl)
        self.assertTrue(al.isValid())
        vl.setAuxiliaryLayer(al)

        # Add a field in auxiliary layer
        p = QgsPropertyDefinition('myprop', QgsPropertyDefinition.DataTypeNumeric, '', '', 'me')
        self.assertFalse(al.exists(p))
        self.assertTrue(al.addAuxiliaryField(p))
        self.assertTrue(al.exists(p))

        # Count auxiliary features
        self.assertEqual(al.featureCount(), 0)

        # Set value for auxiliary fields
        req = QgsFeatureRequest().setFilterExpression("name = 'Honey'")
        f = QgsFeature()
        vl.getFeatures(req).nextFeature(f)
        self.assertTrue(f.isValid())
        afName = QgsAuxiliaryLayer.nameFromProperty(p, True)
        index = vl.fields().indexOf(afName)
        vl.changeAttributeValue(f.id(), index, 333)

        # Count auxiliary features
        self.assertEqual(al.featureCount(), 1)

        # Clear and count
        al.clear()
        self.assertEqual(al.featureCount(), 0)
开发者ID:,项目名称:,代码行数:35,代码来源:

示例2: testCreateSaveOpenStorageWithProject

    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))
开发者ID:,项目名称:,代码行数:16,代码来源:

示例3: testSetAuxiliaryLayer

    def testSetAuxiliaryLayer(self):
        s = QgsAuxiliaryStorage()
        self.assertTrue(s.isValid())

        # Create a new auxiliary layer with 'pk' as key
        vl = createLayer()
        pkf = vl.fields().field(vl.fields().indexOf('pk'))
        al = s.createAuxiliaryLayer(pkf, vl)
        self.assertTrue(al.isValid())
        vl.setAuxiliaryLayer(al)

        self.assertIsNotNone(vl.auxiliaryLayer())

        # Clear auxiliary layer
        al.clear()
        # Remove auxiliary layer
        vl.setAuxiliaryLayer()

        self.assertIsNone(vl.auxiliaryLayer())
开发者ID:,项目名称:,代码行数:19,代码来源:

示例4: testCreateProperty

    def testCreateProperty(self):
        s = QgsAuxiliaryStorage()
        self.assertTrue(s.isValid())

        # Create a new auxiliary layer with 'pk' as key
        vl = createLayer()
        pkf = vl.fields().field(vl.fields().indexOf('pk'))
        al = s.createAuxiliaryLayer(pkf, vl)
        self.assertTrue(al.isValid())
        vl.setAuxiliaryLayer(al)

        # Create a new labeling property on layer without labels
        key = QgsPalLayerSettings.PositionX
        index = QgsAuxiliaryLayer.createProperty(key, vl)
        self.assertEqual(index, -1)

        vl.setLabeling(QgsVectorLayerSimpleLabeling(QgsPalLayerSettings()))
        index = QgsAuxiliaryLayer.createProperty(key, vl)

        p = QgsPalLayerSettings.propertyDefinitions()[key]
        afName = QgsAuxiliaryLayer.nameFromProperty(p, True)
        afIndex = vl.fields().indexOf(afName)
        self.assertEqual(index, afIndex)
开发者ID:,项目名称:,代码行数:23,代码来源:

示例5: testCreateSaveOpenStorageWithString

    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())
开发者ID:,项目名称:,代码行数:57,代码来源:

示例6: testAuxiliaryFieldWidgets

    def testAuxiliaryFieldWidgets(self):
        # Init storage
        s = QgsAuxiliaryStorage()
        self.assertTrue(s.isValid())

        # Create a new auxiliary layer with 'pk' as key
        vl = createLayer()
        pkf = vl.fields().field(vl.fields().indexOf('pk'))
        al = s.createAuxiliaryLayer(pkf, vl)
        self.assertTrue(al.isValid())

        # Set the auxiliary layer to the vector layer
        vl.setAuxiliaryLayer(al)

        # Add a visible property
        p = QgsPropertyDefinition('propName', QgsPropertyDefinition.DataTypeNumeric, '', '', 'user')
        self.assertTrue(al.addAuxiliaryField(p))

        index = al.indexOfPropertyDefinition(p)
        self.assertFalse(al.isHiddenProperty(index))

        afName = QgsAuxiliaryLayer.nameFromProperty(p, True)
        index = vl.fields().indexOf(afName)
        setup = vl.editorWidgetSetup(index)
        self.assertEqual(setup.type(), '')

        tested = False
        for c in vl.attributeTableConfig().columns():
            if c.name == afName:
                self.assertFalse(c.hidden)
                tested = True
                break
        self.assertTrue(tested)

        # Add a hidden property
        p = QgsPalLayerSettings.propertyDefinitions()[QgsPalLayerSettings.PositionX]
        self.assertTrue(al.addAuxiliaryField(p))

        index = al.indexOfPropertyDefinition(p)
        self.assertTrue(al.isHiddenProperty(index))

        afName = QgsAuxiliaryLayer.nameFromProperty(p, True)
        index = vl.fields().indexOf(afName)
        setup = vl.editorWidgetSetup(index)
        self.assertEqual(setup.type(), 'Hidden')

        tested = False
        for c in vl.attributeTableConfig().columns():
            if c.name == afName:
                self.assertTrue(c.hidden)
                tested = True
                break
        self.assertTrue(tested)

        # Add a color property
        p = QgsSymbolLayer.propertyDefinitions()[QgsSymbolLayer.PropertyFillColor]
        self.assertTrue(al.addAuxiliaryField(p))

        index = al.indexOfPropertyDefinition(p)
        self.assertFalse(al.isHiddenProperty(index))

        afName = QgsAuxiliaryLayer.nameFromProperty(p, True)
        index = vl.fields().indexOf(afName)
        setup = vl.editorWidgetSetup(index)
        self.assertEqual(setup.type(), 'Color')
开发者ID:,项目名称:,代码行数:65,代码来源:


注:本文中的qgis.core.QgsAuxiliaryStorage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。