我想从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'