如何获取shapefile的特征数量?

时间:2019-12-12 15:15:47

标签: python shapefile

我想从shapefile中获取特征数量,但无法正确处理。 这里的代码:

import ogr

# Open the shapefile and get the first layer
datasource = ogr.Open("E:HP_Python/GeospatialDevelopmentByExampleWithPython/ExampleData/data/world_borders_simple.shp")

layer = datasource.GetLayerByIndex(0)

print("Number of features:{}".format(layer.GetFeatureCount()))

在此错误消息:

AttributeError                            Traceback (most recent call last)
<ipython-input-1-b694e03f871f> in <module>()
      2 # Open the shapefile and get the first layer
      3 datasource = ogr.Open("E:HP_Python/GeospatialDevelopmentByExampleWithPython/ExampleData/data/world_borders_simple.shp")
----> 4 layer = datasource.GetLayerByIndex(0)
      5 print("Number of features:{}".format(layer.GetFeatureCount()))

AttributeError: 'NoneType' object has no attribute 'GetLayerByIndex'

0 个答案:

没有答案