I have the Lat Lon information of the boundaries of 43 shapefiles. Now I want to combine all these 43 polygons into a single shapefile. How can I do that?

What I did is I converted every polygon to a single shapefile and trying to run this code to combine them to a single shapefile.

import os
import ogr

outputMergefn = 'Merge.shp'
directory = r'G:\ARSI\LAndsat data\Field\Hartford\12022018\shapefiles\\'
#filestartswith = 'C'
FileEndsWith = '.shp'
drivername = 'ESRI Shapefile'
geometrytype = ogr.wkbMultiPoint
ptdriver = ogr.GetDriverByName('ESRI Shapefile')

if os.path.exists(outputMergefn):
out_ds = ptdriver.CreateDataSource(outputMergefn)
out_layer = out_ds.CreateLayer(outputMergefn, geom_type = geometrytype)

filelist = os.listdir(directory)
for file in filelist:
    if file.endswith(FileEndsWith):
        ds = ogr.Open(directory + file)
        if ds is None:
            print("This is None")
        lyr = ds.GetLayer()
        for feat in lyr:
            out_feat = ogr.Feature(out_layer.GetLayerDefn())

But, the merged shapefile does not show any information in QGIS, looks like its empty. Is there any way I can convert the Lat Lon information of multiple polygons to a single shapefile?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.