import fiona from number_of_trees_shp import number_of_trees_shp import csv shape = fiona.open(('Downloads/GAVL_Pilot_Area_Plots.shp')) mainObj = {} polygonNum = 0 rr = 1 storingFileName = 'palm_table_land.csv' with open(storingFileName, 'w', newline='') as file: writer = csv.writer(file) writer.writerow(["Polygon ID", "Farmer Phone Number", "Field Area"]) try: while rr == 1: polygonObj = shape.next() polygonProperties = polygonObj["properties"] polygonName = polygonProperties["Name"] fieldArea = polygonProperties["area"] polygonGeometry = polygonObj["geometry"] polygonPoints = polygonGeometry["coordinates"] phoneNumber = polygonProperties["phoneNumbe"] row = [polygonName, phoneNumber, fieldArea] #print(polygonName) #print(phoneNumber) writer.writerow(row) tempObj = {} tempObj["Area"] = fieldArea pointNum = 0 allPointsObj = {} for i in polygonPoints: for k in i: singlePointobj = k #print(singlePointobj) singlePointLat = singlePointobj[1] singlePointLong = singlePointobj[0] tempPoint = {} tempPoint["Latitude"] = singlePointLat tempPoint["Longitude"] = singlePointLong allPointsObj[("P_"+str(pointNum))] = tempPoint pointNum = pointNum+1 tempObj["Coordinates"] = allPointsObj mainObj[polygonName] = tempObj polygonNum = polygonNum + 1 except: aaa = 1 print(polygonNum) #print(mainObj) #number_of_trees_shp(mainObj)