如何制作一个计算qgis中特征属性的程序?

问题描述

我制作了计算功能的程序。 代码如下。

from osgeo import ogr
import os
path = 'C:/~'
datasource = driver.open(tree,0)
layer = datasource.Getlayer()
featureCount = layer.GetFeatureCount()
print("path = ",featureCount)

如何添加用于计算每个属性代码? 我需要帮助,而不是医生

解决方法

我不是很清楚你所说的计算属性是什么意思。但是一旦你有了一个层,它就是 easy to iterate through the features and access the attributes of each feature:

for feature in layer.getFeatures():
     print(feature['name'])
     print(feature[0])

您还可以查询图层以获取每个要素将具有的属性的详细信息:

for field in layer.fields():
    print(field.name(),field.typeName())