GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 259 forks source link

How do I concatenate two shapefiles/DBF files #137

Closed mohammedayub44 closed 6 years ago

mohammedayub44 commented 6 years ago

I looked through the documentation of this library. I could not find any reference to append or add records to existing shapefiles or concatenate shapefiles. etc. I'm I missing something on the Wiki page?

karimbahgat commented 6 years ago

We don't currently have a lot of recipes like that in the documentation, although it might be good to add. Here's an example from Joel's website if you're using version <1.2.x. Or if you're using version 2.x, this should work:

w = shapefile.Writer()
w.fields = [] # define fields here, maybe read from first shapefile
for f in filepaths:
    r = shapefile.Reader(f)
    for sr in r.iterShapeRecords():
        w.record(*sr.record)
        w.shape(sr.shape)