I am trying to strip data out of an existing shapefile to create new shapefiles. I have made the loop work, and made the new file, but I cannot work out why I cannot add records to the new file I am writing:
import shapefile as shp
coord1 = (39.737094, -121.543857)
coord2 = (39.651237, -121.403610)
sfinput = shp.Reader(r'C:\...\fire_archive_M6_98806.shp')
w = shp.Writer(r'C:\...\Output')
w.fields = sfinput.fields
for i in range(len(sfinput.records())):
#test if within latitude
if sfinput.record(i)[0] >= coord2[0] and sfinput.record(i)[0] <= coord1[0]:
#test if within longitude
if sfinput.record(i)[1] <= coord2[1] and sfinput.record(i)[1] >= coord1[1]:
w.record(sfinput.record(i))
The error I am recieving:
record = [recordList[i] for i in range(fieldCount)]
IndexError: tuple index out of range
fieldCount
sounds like the number of attributes, whilerecordList
sounds like the number of records.w.record=sfinput.record(i)
This just seems to write over the record already assigned tow
though