The purpose is to read coordinates from a file, it survey traverse. The following is what it is supposed to do:
#Start at point A and going clockwise around the traverse list the coordinates:
#Cross multiply in one direction; 500.000*2000.000=647,228.0
#Cross multiply in the other direction;
#Add up the columns of the products which is 3,384,174.1 |3,590,045.6
#Using Area Equation to compute the area; difference of 2 columns divided by 2
#Point file contains
#Point,N,E
#A,500.000,2000.000
#B,323.614,1561.426
#C,526.996,1488.321
#D,719.336,1686.956
import math, os, csv
#Reading the file from here
def getcoord():
myfile= input('Enter the path of file : ')
filename = 'CoordsT.txt'
with open('filename', 'r') as csvfile:
reader = csv.reader(csvfile)
next(reader)
return list(reader)
data=[]
for row in reader:
Name=row[0]
E=float(row[1])
N=float(row[2])
data.append([Name,E,N])
return data
def areacalculation(data): #function that calculate the area of polygon
n=len(data)
semiarea= 0.0
j = n - 1#
if n>=3:
for i in range(0,n):
semiarea += (data[j][1] + data[i][1]) * (data[j][2]- data[i][2])
j = i # j is previous vertex to i
area=abs(semiarea/2.0)
return area,n
else:
print('Enter at least 3 sides of polygon')
def polygontype(n): #function that gives the type of polygon, takes argument
dictionary={3:"Triangle",4:"Quadrilateral",5:"Pentagon",6:"Hexagon",7:"Heptagon",8:"Octagon",9:"Nonagon"}
b=dictionary[n]
return b
def square_metre(area): #function with argument
A2=int(area)
return (A2)
def hectares(area): # fuction with argument
A1=area
return "%.4f"%(A1)
#the error am getting comes from this block
def main():
instruction()
EN_data= getcoord()
a,No_ofsides=areacalculation(EN_data) #the problem is here
hectares(a)
sqm=square_metre(a)
polytyp=polygontype(No_ofsides)
return EN_data
if a>10000:
area_hec=hectares(a/10000.00)
print('The area of',polytyp,'is',area_hec,'Hectares')
else:
print('The area of',polytyp,'is',sqm,'Square Metres')
main()