打开shp
from osgeo import ogr
inshp_path = 'D:\mycode\GISandPython\0data\park_point_shp\xiamen_20181128_park.shp'
driver = ogr.GetDriverByName('ESRI Shapefile') #查找一个特定的驱动程序
datasource = driver.Open(inshp_path, 0) #0只读,1可写
dir( datasource) #使用Python的内省函数dir()查看所有方法
遍历所有属性值
#【遍历所有属性值】
for i in range(feature.GetFieldCount() ):
print( feature.GetField(i) )
### 【查看表的结构,各个字段的名称等信息】在layer附加信息中看
layerdef = layer.GetLayerDefn()
for i in range(layerdef.GetFieldCount() ):
defn = layerdef.GetFieldDefn(i)
print(defn.GetName(), defn.GetWidth(), defn.GetType(), defn.GetPrecision() )