本文整理汇总了Python中qgis.core.QgsFeatureStore类的典型用法代码示例。如果您正苦于以下问题:Python QgsFeatureStore类的具体用法?Python QgsFeatureStore怎么用?Python QgsFeatureStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsFeatureStore类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testProxyFeatureSink
def testProxyFeatureSink(self):
fields = QgsFields()
fields.append(QgsField('fldtxt', QVariant.String))
fields.append(QgsField('fldint', QVariant.Int))
store = QgsFeatureStore(fields, QgsCoordinateReferenceSystem())
proxy = QgsProxyFeatureSink(store)
self.assertEqual(proxy.destinationSink(), store)
self.assertEqual(len(store), 0)
f = QgsFeature()
f.setAttributes(["test", 123])
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
proxy.addFeature(f)
self.assertEqual(len(store), 1)
self.assertEqual(store.features()[0]['fldtxt'], 'test')
f2 = QgsFeature()
f2.setAttributes(["test2", 457])
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(200, 200)))
f3 = QgsFeature()
f3.setAttributes(["test3", 888])
f3.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(300, 200)))
proxy.addFeatures([f2, f3])
self.assertEqual(len(store), 3)
self.assertEqual(store.features()[1]['fldtxt'], 'test2')
self.assertEqual(store.features()[2]['fldtxt'], 'test3')
示例2: testFromIterator
def testFromIterator(self):
"""
Test adding features from an iterator
:return:
"""
layer = createLayerWithFivePoints()
store = QgsFeatureStore(layer.fields(), layer.crs())
self.assertTrue(store.addFeatures(layer.getFeatures()))
vals = [f['fldint'] for f in store.features()]
self.assertEqual(vals, [123, 457, 888, -1, 0])