问题描述
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())