简体   繁体   English

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

[英]How can I make a program that count features' attributes in qgis?

I made the program that count features.我制作了计算功能的程序。 Code is Below is the following.代码如下。

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

How can I add the code for counting each attributes?如何添加用于计算每个属性的代码? I need help, not doctor我需要帮助,而不是医生

I'm not entirely clear on what you mean by count the attributes.我不完全清楚你所说的计算属性是什么意思。 But once you have a layer it is easy to iterate through the features and access the attributes of each feature :但是一旦你有了一个层, 就很容易遍历这些特征并访问每个特征的属性

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

You can also query the layer for details of the attributes that each feature will have:您还可以查询图层以获取每个要素将具有的属性的详细信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM