Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define the main function
- import re
- import math
- from Tkinter import *
- import tkFileDialog
- class GuiFrame1(Frame):
- def __init__ (self):
- Frame.__init__(self)
- self.master.geometry("500x500")
- self.pack(expand = 1, fill = BOTH)
- self.FileOpenerButton = Button(self,\
- text = "Open File", command = self.OpenFile)
- self.FileOpenerButton.pack()
- def OpenFile(self):
- inputFile = tkFileDialog.askopenfile()
- inputFile.close()
- def main():
- with open ("LotData1.txt", "r") as file:
- sideList = []
- for i in file:
- tmp = i.strip().split()
- sideList.append([tmp[0], tmp[1], float(tmp[2])])
- obj = Lot(sideList, "", "")
- departures = obj.getDepartureClosure()
- latitudes = obj.getLatitudeClosure()
- departures_correction = obj.getDepartureCorrectedClosure()
- latitudes_correction = obj.getLatitudeCorrectedClosure()
- lec = obj.getLinearErrorOfClosure()
- totaldist = obj.getTotalDistance()
- depclosure = sum(departures)
- latclosure = sum(latitudes)
- relprecision = obj.getRelativePrecision()
- linearbearing = obj.getLECBearingToString()
- count = len(sideList)
- print "INPUT VALUES:\nCOURSE\tBEARING\t\tDISTANCE\t\tLATITUDE\tCORRECTION\tDEPARTURE\tCORRECTION"
- for i in range(count):
- print "%s \t %s \t %+6.3f\t%+10.3f\t%+10.3f\t%+10.3f\t%+10.3f"%\
- (sideList[i][0], sideList[i][1], sideList[i][2], latitudes[i], latitudes_correction[i], departures[i], departures_correction[i])
- adj_atitudeclosure, adj_departureclosure, adj_distance = obj.adjustByCompassRule()
- print "\n\nADJUSTED VALUES:\nCOURSE\tLATITUDE\tDEPARTURE\tDISTANCE\tBEARING"
- for i in range(count):
- #print sideList[i][0], adj_atitudeclosure[i], adj_departureclosure[i], adj_distance[i]
- print "%s\t%+10.3f\t%+10.3f\t%+10.3f\t%5d-%2.0f-%2.0f"%\
- (sideList[i][0], adj_atitudeclosure[i], adj_departureclosure[i], adj_distance[i],obj.convert_to_DMS()[0][i],obj.convert_to_DMS()[1][i],obj.convert_to_DMS()[2][i])
- print
- print "OTHER STATISTICS:"
- print " LATITUDE CLOSURE:", latclosure
- print " DEPARTURE CLOSURE:", depclosure
- print
- print " LINEAR ERROR OF CLOSURE (LEC):", lec
- print " LEC BEARING: ", linearbearing
- print
- print " TOTAL DISTANCE:", totaldist
- print " RELATIVE PRECISION: 1:", relprecision
- # use the tehcnical description info from input file to build a list called sideList
- # containing the parsed Side objects
- # pass this sideList to the self.sideList of in the of Lot object (via constructor)
- # assume a 0.00 Northing and 0.00 Easting for the initial lot corner
- # pass the assumed start coordinates to the Lot object
- # class Lot will process/adjust the self.sideList using compass rule
- # get a reference of the Lot's processed/adjusted self.sideList
- # iterate the copied sideList to print the initial/raw values
- # iterate the copied sideList to print the adjusted values
- # iterate the copied sideList to print the adjusted coordinates
- # use the Lot object to print the other needed info/statistics
- #with open ("LotDataSummary.txt","w") as file2:
- # write the output values to an output file
- # Tip: make a concatenated string of results to be outputted before writing it on a file
- # that is, output_file.write(concatenated_string_output)
- # hence, write() is recommended to be used only once, i.e last part
- # make sure to include "\n" in concatenating strings
- # close the input and output files
- class Lot:
- def __init__(self, sideList, initialNorthing, initialEasting):
- # initialize the instance variables here
- self.sideList = sideList
- self.initialNorthing = initialNorthing
- self.initialEasting = initialEasting
- # returns the self.sideList of this Lot object
- def getSideList(self):
- return self.SideList
- # returns the total distance of the Lot
- # by iterating through the self.sideList's distances
- def getTotalDistance(self):
- #totaldist = 0
- #for row in self.sideList:
- # totaldist += row[2]
- TotalDistance = sum([row[2] for row in self.sideList ])
- return TotalDistance
- def convertBearingStringToRadians(self, format_input):
- """
- Coordinate format conversion
- degrees minutes seconds:
- decimal degrees = degrees + minutes}/60 + seconds/3600.
- """
- degrees, minutes, seconds = map(float, re.match("\w(\d+)-(\d+)-(\d+)\w", format_input).groups())
- degrees = degrees + minutes/60 + seconds/3600
- return math.radians(degrees)
- def convert_to_DMS(self):
- Temporary_DMS = []
- DMS = []
- DMS2 = []
- DMS3= []
- for i in range(len(self.adjustByCompassRule()[0])):
- Temporary_DMS+=[math.degrees(math.atan(abs(self.adjustByCompassRule()[1][i])/abs(self.adjustByCompassRule()[0][i])))]
- for i in Temporary_DMS:
- degrees = int(i)
- temp = 60 * (i - degrees)
- minutes = int(temp)
- seconds = 60 * (temp - minutes)
- roundsec = round(seconds, 2)
- DMS += [degrees]
- DMS2 += [minutes]
- DMS3 += [roundsec]
- return DMS, DMS2, DMS3
- # returns the departure closure of the Lot
- # by iterating through the self.sideList
- def getDepartureClosure(self):
- departureclosure = []
- for row in self.sideList:
- rads = self.convertBearingStringToRadians(row[1])
- if "W" in row[1]:
- departure = row[2]*math.sin(rads) * -1
- else:
- departure = row[2]*math.sin(rads)
- departureclosure.append(departure)
- return departureclosure
- # returns the latitude closure of the Lot
- # by iterating through the self.sideList
- def getLatitudeClosure(self):
- latitudeclosure = []
- for row in self.sideList:
- rads = self.convertBearingStringToRadians(row[1])
- if "S" in row[1]:
- latitude = row[2]*math.cos(rads) * -1
- else:
- latitude = row[2]*math.cos(rads)
- latitudeclosure.append(latitude)
- return latitudeclosure
- # returns the corrected departure closure of the Lot
- # by iterating through the self.sideList
- def getDepartureCorrectedClosure(self):
- departureclosure = sum(self.getDepartureClosure())
- total_distance = self.getTotalDistance()
- departures_correction = []
- for row in self.sideList:
- correction = -row[2] * departureclosure/ total_distance
- departures_correction.append(correction)
- return departures_correction
- # returns the corrected latitude closure of the Lot
- # by iterating through the self.sideList
- def getLatitudeCorrectedClosure(self):
- latitudeclosure = sum(self.getLatitudeClosure())
- total_distance = self.getTotalDistance()
- latitudes_correction = []
- for row in self.sideList:
- correction = -row[2] * latitudeclosure/ total_distance
- latitudes_correction.append(correction)
- return latitudes_correction
- # returns the linear error of closure or LEC
- # you might use the sqrt() and pow() here
- def getLinearErrorOfClosure(self):
- total_latitude = sum(self.getLatitudeClosure())
- total_departure = sum(self.getDepartureClosure())
- latidep = math.pow(total_departure, 2) + math.pow(total_latitude, 2)
- LinearError = math.sqrt(latidep)
- return LinearError#This is my code, I'm not sure why it not working
- # returns the bearing of LEC converted to String
- # uses B = arctan(-depCorr/-latCorr)
- # you must find a way to determine what quadrant a given depCor and latCorr lie
- # you might want to use abs(), math.atan(), and math.degrees()
- def getLECBearingToString(self):
- total_latitude = sum(self.getLatitudeClosure())
- total_departure = sum(self.getDepartureClosure())
- lecbearing = math.degrees(math.atan(abs(total_departure)/abs(total_latitude)))
- Temporary_DMS = [lecbearing]
- DMS = 0
- DMS2 = 0
- DMS3= 0
- for i in Temporary_DMS:
- degrees = int(i)
- temp = 60 * (i - degrees)
- minutes = int(temp)
- seconds = 60 * (temp - minutes)
- roundsec = round(seconds, 1)
- DMS += degrees
- DMS2 += minutes
- DMS3 += roundsec
- return DMS, DMS2, DMS3
- #this is still in degrees, how do i convert this back to bearing like N30-30-30W
- # returns the Relative Precision of the Lot
- # Relative Precision (RP) is defined in GE books
- # you might want to use sqrt() and pow()
- def getRelativePrecision(self):
- #the Relative precision is just ratio of 1:(total distance/LEC).
- #this prints something like 1:203 when we print it in the block. #this should be
- #just a number and no decimal.
- total_distance = self.getTotalDistance()
- linearerror = self.getLinearErrorOfClosure()
- relativeprecision = total_distance/linearerror
- return relativeprecision
- # adjusts the Lot using compass rule
- # you might use abs(), math.degrees(), math.atan(), sqrt(), and pow()
- def adjustByCompassRule(self):
- count = len(self.sideList)
- latitude_closure = self.getLatitudeClosure()
- latitudes_correction = self.getLatitudeCorrectedClosure()
- adj_atitudeclosure = [ latitude_closure[i] + latitudes_correction[i] for i in range(count)]
- departure_closure = self.getDepartureClosure()
- departures_correction = self.getDepartureCorrectedClosure()
- adj_departureclosure = [ departure_closure[i] + departures_correction[i] for i in range(count)]
- adj_distance = [ math.sqrt(adj_atitudeclosure[i]*adj_atitudeclosure[i] + adj_departureclosure[i]*adj_departureclosure[i]) for i in range(count)]
- return adj_atitudeclosure, adj_departureclosure, adj_distance
- # iterate the self.sideList
- # for each side object
- # set the departureCorrection
- # set the departureCorrected
- # and so on..
- # iterate the self.sideList
- # for each side
- # set the angleCorrected of the side's Bearing
- # set the distanceCorrected of the side
- # iterate the self.sideList
- # use the Lot's initialNorthing and initialEasting to set the very first endpoint
- # for each side
- # set the northing of the side's first endpoint
- # set the easting of the side's first endpoint
- # set the northing of the side's second endpoint
- # set the easting of the side second endpoint
- # function to compute the area using the Area by Coordinates method
- # it iterates through the self.sideList and gets the adjusted coordinates of the endPoints and compute the enclosed area
- # you might use abs() here
- def computeAreaByCoordinates(self):
- pass
- class Side:
- def __init__(self, sideName, Bearing_bearing, double_distance):
- # initialize the instance variables here
- self.sideName = sideName
- self.bearing = bearing
- self.distance = distance
- # you might use the math.sin(), math.cos(), and math.radians() here
- # you might use the getDepartureSign() and getLatitudeSign() methods of the Bearing class
- # other initial processing goes here, set their initial values if possible
- # otherwise, set a default value
- self.departure = math.sin(math.radians())
- self.latitude = math.cos(math.radians())
- # this variable refer to the 2 EndPoint objects of a Side
- # a Tuple data structure is recommended since it has a fixed length of 2
- self.endPoints = 0.00
- self.departureCorrection = 0.00
- self.latitudeCorrection = 0.00
- self.departureCorrected = 0.00
- self.latitudeCorrected = 0.00
- self.distanceCorrected = 0.00
- # declare the set and get methods of ALL the instance variables here,
- # especially setEndPoints() and getEndPoints()
- class Bearing:
- def __init__(self, angle, anglePrefix, angleSuffix):
- # check first if the input String is a valid Bearing value,
- # of the form 'N12-34-56W' or 'S12-34-56E'
- # anglePrefix is one of 'N' or 'S'
- # angleSuffix is one of 'E' or 'W'
- # initialize ALL instance variable except angleCorrected
- # you might use string slicing here and string's split()
- self.angle = angle
- self.angleCorrected = 0.00
- self.anglePrefix = anglePrefix
- self.angleSuffix = angleSuffix
- def setAngleCorrected(self, angleCorrected):
- pass
- # GET methods for the instance variables
- def getAngle(self):
- pass
- def getAngleCorrected(self):
- pass
- def getAnglePrefix(self):
- pass
- def getAngleSuffix(self):
- pass
- # returns the departure sign/flag (-1 or +1) given the current Bearing's anglePrefix and angleSuffix
- # hint: determine the quadrant given the current Bearing's anglePrefix and angleSuffix
- def getDepartureSign(self):
- if angleSuffix.startswith("W"):
- return -1* departure
- else:
- return departure
- # returns the latitude sign/flag (-1 or +1) given the current Bearing's anglePrefix and angleSuffix
- # hint: determine the quadrant given the current Bearing's anglePrefix and angleSuffix
- def getLatitudeSign(self):
- if anglePrefix.startswith("S"):
- return -1* latitude
- else:
- return latitude
- # returns the concatenated anglePrefix+<angle>+angleSuffix
- # <angle> is of the form DD-MM-SS
- # returns "N45-23-12W" for instance
- def bearingToString(self):
- pass
- # returns the concatenated anglePrefix+<angleCorrected>+angleSuffix
- # <angleCorrected> is of the form DD-MM-SS
- # returns the corrected "N45-23-12W" for instance
- def bearingCorrectedToString(self):
- pass
- class EndPoint:
- def __init__(self, endPointID):
- # in a given Lot's Side, say Side AB,
- # endPointID is either A or B
- # hence, one Side has 2 endPointIDs
- self.endPointID = endPointID
- # could be set to 0.00 first and then modified later
- # if the corrected dep and lat is known after compass rule
- self.northing = 0.00
- self.easting = 0.00
- # set and get methods for ALL instance variable
- # run the main function
- main()
- GuiFrame1().mainloop()
Advertisement
Add Comment
Please, Sign In to add comment