I would like to generate a .shp with five points using shapefile available through pyshp
. However, when I loop through my list I get only the last value. This makes sense as I did not append any of the points to an empty list (e.g. new_shp = []
)
import shapefile as sf
import os
filename2 = 'test/point10'
lis = [(33.21, -122.15, 'france'), (35.31, -122.15, 'germany'), (35.41, -123.15, 'Hawaii'), (30.51, -122.15, 'Philippines'),(32.30, -122.15, 'Texas')]
for l in lis:
w = sf.Writer(sf.POINT)
w.point(l[0], l[1])
w.field('location')
w.record(l[2], 'Point')
w.save(filename2)
# create the PRJ file
prj = open("%s.prj" % filename2, "w")
epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
prj.write(epsg)
prj.close()
I am assumming that I have to append all the points somewhere in the for loop, but I don't understand how to actually append it. How do I effectively loop through lis to get a .shp file with all five points?