I am trying to create shapefile from csv data using shapefile.py but i am constantly getting this error,
Traceback (most recent call last):
File "createShp_Davis.py", line 31, in <module>
w.save(File_loc)
File "/usr/lib/python2.7/dist-packages/shapefile.py", line 862, in save
self.saveShp(target)
File "/usr/lib/python2.7/dist-packages/shapefile.py", line 829, in saveShp
self.__shapefileHeader(self.shp, headerType='shp')
File "/usr/lib/python2.7/dist-packages/shapefile.py", line 586, in __shapefileHeader
raise ShapefileException("Failed to write shapefile bounding box. Floats required.")
shapefile.ShapefileException: Failed to write shapefile bounding box. Floats required.
For some reason it is not saving the shapefile properly, it is able to create .shp file but that's it. There are no .dbf or .shx. I believe i am making some mistake somewhere in the code, but not sure where. Here is my code.
#!/usr/bin/python
import csv
import shapefile
import BIL
File_loc = raw_input("Enter the file name and folder location: ")
w = shapefile.Writer(shapefile.POINT)
w.field('Species_Id')
w.field('Species')
w.field('MeanAnnTemp')
w.field('TempSeasonality')
w.field('MinTempColdestMonth')
w.field('AnnPrecipitation')
#w.field('Elevation')
w.field('Latitude')
w.field('Longitude')
with open('treeMap.csv', 'rb') as f:
reader = csv.reader(f)
for rec in reader:
w.point(rec[6],rec[5])
lat=[];lon=[]
lat.append(rec[5]);lon.append(rec[6])
lat=[float(i) for i in lat];lon=[float(i) for i in lon]
MAT=BIL.lookupBIL(r'./worldclim/bio1',lat,lon)
TSD=BIL.lookupBIL(r'./worldclim/bio4',lat,lon)
AnnTMin=BIL.lookupBIL(r'./worldclim/bio6',lat,lon)
ANNPREC=BIL.lookupBIL(r'./worldclim/bio12',lat,lon)
w.record(rec[2], rec[3], MAT[0], TSD[0], AnnTMin[0], ANNPREC[0], rec[5], rec[6])
w.save(File_loc)
print "Shapefile Successfully created"