

def line_to_point_layer(ds, line_name, pt_name):
    'Creates a point layer from vertices in a line layer.'
    if ds.GetLayer(pt_name):
        ds.DeleteLayer(pt_name)
    line_lyr = ds.GetLayer(line_name)
    sr = line_lyr.GetSpatialRef()
    pt_lyr = ds.CreateLayer(pt_name, sr, ogr.wkbPoint)
    pt_lyr.CreateFields(line_lyr.schema)
    pt_feat = ogr.Feature(pt_lyr.GetLayerDefn())
    pt_geom = ogr.Geometry(ogr.wkbPoint)
    for line_feat in line_lyr:
        atts = line_feat.items()
        for fld_name in atts.keys():
            pt_feat.SetField(fld_name, atts[fld_name])
        for coords in line_feat.geometry().GetPoints():
            pt_geom.AddPoint(*coords)
            pt_feat.SetGeometry(pt_geom)
            pt_lyr.CreateFeature(pt_feat)

dataset/ETHPy150Open cgarrard/osgeopy-code/Chapter6/listing6_1.py line_to_point_layer/original