dkoug Blog

Read Shapefile with GDAL

Python -- Posted on Sept. 2, 2018

Read Shapefile with gdal

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from osgeo import ogr
shapefile = ogr.Open("shapefile.shp")
layer = shapefile.GetLayer(0)
crs = layer.GetSpatialRef()
print(crs)
print(crs.GetAttrValue('AUTHORITY',1))
for i in range(layer.GetFeatureCount()):
    feature = layer.GetFeature(i)
    print(feature.GetGeometryRef())
    geometry = feature.GetGeometryRef()