def write_line_shp(line_list, out_shp): """Export ESRI Shapefile -- Line feature""" print('Write line shapefile: %s' % out_shp) driver = ogr_GetDriverByName(str('ESRI Shapefile')) if driver is None: print('ESRI Shapefile driver not available.') sys.exit(1) if os.path.exists(out_shp): driver.DeleteDataSource(out_shp) ds = driver.CreateDataSource(out_shp.rpartition(os.sep)[0]) if ds is None: print('ERROR Output: Creation of output file failed.') sys.exit(1) lyr = ds.CreateLayer(str(out_shp.rpartition(os.sep)[2].split('.')[0]), None, wkbLineString) for l in line_list: line = ogr_Geometry(wkbLineString) for i in l: line.AddPoint(i[0], i[1]) templine = ogr_CreateGeometryFromJson(line.ExportToJson()) feature = ogr_Feature(lyr.GetLayerDefn()) feature.SetGeometry(templine) lyr.CreateFeature(feature) feature.Destroy() ds.Destroy()