I am looking to do a simple append using Pyshp and keep running into walls. The editor object could not read the dbf header for the input shapefile so I tried using reader and writer as suggested but have run into some problems with writer.
Initially I wanted to copy entire ShapeRecord objects but did not see a way to use writer to write them, so I tried a more granular approach like iterating and copying shape and record attributes which failed as well:
reader = shapefile.Reader('c:/temp/input.shp') #Open input file w = shapefile.Writer(shapefile.POLYGON) #Create writer w.field('FLD1','C','20') #Create fields w.field('FLD2','C','20') w.field('FLD3','C','20') w.field('FLD4','C','20') w.field('FLD5','N','20') w.field('FLD6','N','20') w.field('FLD7','C','20') for sr in reader.shapeRecords(): #iterate through shapeRecords in the input w.poly(sr.shape) #write shape to writer w.record(sr.record) #write record to writer w.save('c:/temp/appendoutput.shp') #save writer to file
I end up with two errors:
IndexError: tuple index out of range for
w.record(sr.record)File "C:\Python26\ArcGIS10.0\lib\shapefile.py", line 959, in record [record.append(recordList[i]) for i in range(fieldCount)]
This perplexes me since print sr.record shows me that there are seven items in the record list that was read in by the reader and I have seven fields.
TypeError: iteration over non-sequence for the
Thanks again for any recommendations :)