Guest User

Code1

a guest
May 27th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.29 KB | None | 0 0
  1. #define the main function
  2.  
  3. import re
  4. import math
  5. from Tkinter import *
  6. import tkFileDialog
  7.  
  8. class GuiFrame1(Frame):
  9. def __init__ (self):
  10. Frame.__init__(self)
  11. self.master.geometry("500x500")
  12. self.pack(expand = 1, fill = BOTH)
  13.  
  14. self.FileOpenerButton = Button(self,\
  15. text = "Open File", command = self.OpenFile)
  16. self.FileOpenerButton.pack()
  17.  
  18. def OpenFile(self):
  19. inputFile = tkFileDialog.askopenfile()
  20.  
  21.  
  22. inputFile.close()
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. def main():
  41. with open ("LotData1.txt", "r") as file:
  42. sideList = []
  43. for i in file:
  44. tmp = i.strip().split()
  45. sideList.append([tmp[0], tmp[1], float(tmp[2])])
  46.  
  47.  
  48.  
  49. obj = Lot(sideList, "", "")
  50. departures = obj.getDepartureClosure()
  51. latitudes = obj.getLatitudeClosure()
  52. departures_correction = obj.getDepartureCorrectedClosure()
  53. latitudes_correction = obj.getLatitudeCorrectedClosure()
  54. lec = obj.getLinearErrorOfClosure()
  55. totaldist = obj.getTotalDistance()
  56. depclosure = sum(departures)
  57. latclosure = sum(latitudes)
  58. relprecision = obj.getRelativePrecision()
  59. linearbearing = obj.getLECBearingToString()
  60.  
  61. count = len(sideList)
  62.  
  63. print "INPUT VALUES:\nCOURSE\tBEARING\t\tDISTANCE\t\tLATITUDE\tCORRECTION\tDEPARTURE\tCORRECTION"
  64. for i in range(count):
  65. print "%s \t %s \t %+6.3f\t%+10.3f\t%+10.3f\t%+10.3f\t%+10.3f"%\
  66. (sideList[i][0], sideList[i][1], sideList[i][2], latitudes[i], latitudes_correction[i], departures[i], departures_correction[i])
  67.  
  68.  
  69. adj_atitudeclosure, adj_departureclosure, adj_distance = obj.adjustByCompassRule()
  70. print "\n\nADJUSTED VALUES:\nCOURSE\tLATITUDE\tDEPARTURE\tDISTANCE\tBEARING"
  71. for i in range(count):
  72. #print sideList[i][0], adj_atitudeclosure[i], adj_departureclosure[i], adj_distance[i]
  73. print "%s\t%+10.3f\t%+10.3f\t%+10.3f\t%5d-%2.0f-%2.0f"%\
  74. (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])
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. print
  85. print "OTHER STATISTICS:"
  86. print " LATITUDE CLOSURE:", latclosure
  87.  
  88. print " DEPARTURE CLOSURE:", depclosure
  89. print
  90. print " LINEAR ERROR OF CLOSURE (LEC):", lec
  91. print " LEC BEARING: ", linearbearing
  92. print
  93. print " TOTAL DISTANCE:", totaldist
  94.  
  95. print " RELATIVE PRECISION: 1:", relprecision
  96. # use the tehcnical description info from input file to build a list called sideList
  97. # containing the parsed Side objects
  98. # pass this sideList to the self.sideList of in the of Lot object (via constructor)
  99. # assume a 0.00 Northing and 0.00 Easting for the initial lot corner
  100. # pass the assumed start coordinates to the Lot object
  101.  
  102. # class Lot will process/adjust the self.sideList using compass rule
  103. # get a reference of the Lot's processed/adjusted self.sideList
  104.  
  105. # iterate the copied sideList to print the initial/raw values
  106. # iterate the copied sideList to print the adjusted values
  107. # iterate the copied sideList to print the adjusted coordinates
  108. # use the Lot object to print the other needed info/statistics
  109.  
  110. #with open ("LotDataSummary.txt","w") as file2:
  111.  
  112.  
  113. # write the output values to an output file
  114. # Tip: make a concatenated string of results to be outputted before writing it on a file
  115. # that is, output_file.write(concatenated_string_output)
  116. # hence, write() is recommended to be used only once, i.e last part
  117. # make sure to include "\n" in concatenating strings
  118. # close the input and output files
  119.  
  120.  
  121. class Lot:
  122. def __init__(self, sideList, initialNorthing, initialEasting):
  123. # initialize the instance variables here
  124. self.sideList = sideList
  125. self.initialNorthing = initialNorthing
  126. self.initialEasting = initialEasting
  127.  
  128. # returns the self.sideList of this Lot object
  129. def getSideList(self):
  130. return self.SideList
  131.  
  132. # returns the total distance of the Lot
  133. # by iterating through the self.sideList's distances
  134. def getTotalDistance(self):
  135. #totaldist = 0
  136. #for row in self.sideList:
  137. # totaldist += row[2]
  138.  
  139. TotalDistance = sum([row[2] for row in self.sideList ])
  140.  
  141. return TotalDistance
  142.  
  143. def convertBearingStringToRadians(self, format_input):
  144. """
  145. Coordinate format conversion
  146. degrees minutes seconds:
  147. decimal degrees = degrees + minutes}/60 + seconds/3600.
  148. """
  149. degrees, minutes, seconds = map(float, re.match("\w(\d+)-(\d+)-(\d+)\w", format_input).groups())
  150. degrees = degrees + minutes/60 + seconds/3600
  151. return math.radians(degrees)
  152.  
  153.  
  154. def convert_to_DMS(self):
  155. Temporary_DMS = []
  156. DMS = []
  157. DMS2 = []
  158. DMS3= []
  159. for i in range(len(self.adjustByCompassRule()[0])):
  160. Temporary_DMS+=[math.degrees(math.atan(abs(self.adjustByCompassRule()[1][i])/abs(self.adjustByCompassRule()[0][i])))]
  161. for i in Temporary_DMS:
  162. degrees = int(i)
  163. temp = 60 * (i - degrees)
  164. minutes = int(temp)
  165. seconds = 60 * (temp - minutes)
  166. roundsec = round(seconds, 2)
  167. DMS += [degrees]
  168. DMS2 += [minutes]
  169. DMS3 += [roundsec]
  170. return DMS, DMS2, DMS3
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. # returns the departure closure of the Lot
  181. # by iterating through the self.sideList
  182. def getDepartureClosure(self):
  183. departureclosure = []
  184. for row in self.sideList:
  185. rads = self.convertBearingStringToRadians(row[1])
  186.  
  187. if "W" in row[1]:
  188. departure = row[2]*math.sin(rads) * -1
  189. else:
  190. departure = row[2]*math.sin(rads)
  191. departureclosure.append(departure)
  192.  
  193. return departureclosure
  194.  
  195.  
  196.  
  197.  
  198.  
  199. # returns the latitude closure of the Lot
  200. # by iterating through the self.sideList
  201. def getLatitudeClosure(self):
  202. latitudeclosure = []
  203. for row in self.sideList:
  204. rads = self.convertBearingStringToRadians(row[1])
  205. if "S" in row[1]:
  206. latitude = row[2]*math.cos(rads) * -1
  207. else:
  208. latitude = row[2]*math.cos(rads)
  209. latitudeclosure.append(latitude)
  210.  
  211. return latitudeclosure
  212.  
  213. # returns the corrected departure closure of the Lot
  214. # by iterating through the self.sideList
  215. def getDepartureCorrectedClosure(self):
  216.  
  217. departureclosure = sum(self.getDepartureClosure())
  218. total_distance = self.getTotalDistance()
  219. departures_correction = []
  220. for row in self.sideList:
  221. correction = -row[2] * departureclosure/ total_distance
  222. departures_correction.append(correction)
  223.  
  224. return departures_correction
  225.  
  226. # returns the corrected latitude closure of the Lot
  227. # by iterating through the self.sideList
  228. def getLatitudeCorrectedClosure(self):
  229. latitudeclosure = sum(self.getLatitudeClosure())
  230. total_distance = self.getTotalDistance()
  231. latitudes_correction = []
  232. for row in self.sideList:
  233. correction = -row[2] * latitudeclosure/ total_distance
  234. latitudes_correction.append(correction)
  235.  
  236. return latitudes_correction
  237.  
  238. # returns the linear error of closure or LEC
  239. # you might use the sqrt() and pow() here
  240. def getLinearErrorOfClosure(self):
  241. total_latitude = sum(self.getLatitudeClosure())
  242. total_departure = sum(self.getDepartureClosure())
  243. latidep = math.pow(total_departure, 2) + math.pow(total_latitude, 2)
  244. LinearError = math.sqrt(latidep)
  245.  
  246. return LinearError#This is my code, I'm not sure why it not working
  247.  
  248. # returns the bearing of LEC converted to String
  249.  
  250. # uses B = arctan(-depCorr/-latCorr)
  251. # you must find a way to determine what quadrant a given depCor and latCorr lie
  252. # you might want to use abs(), math.atan(), and math.degrees()
  253. def getLECBearingToString(self):
  254. total_latitude = sum(self.getLatitudeClosure())
  255. total_departure = sum(self.getDepartureClosure())
  256. lecbearing = math.degrees(math.atan(abs(total_departure)/abs(total_latitude)))
  257.  
  258. Temporary_DMS = [lecbearing]
  259. DMS = 0
  260. DMS2 = 0
  261. DMS3= 0
  262. for i in Temporary_DMS:
  263. degrees = int(i)
  264. temp = 60 * (i - degrees)
  265. minutes = int(temp)
  266. seconds = 60 * (temp - minutes)
  267. roundsec = round(seconds, 1)
  268. DMS += degrees
  269. DMS2 += minutes
  270. DMS3 += roundsec
  271. return DMS, DMS2, DMS3
  272.  
  273.  
  274.  
  275.  
  276. #this is still in degrees, how do i convert this back to bearing like N30-30-30W
  277. # returns the Relative Precision of the Lot
  278. # Relative Precision (RP) is defined in GE books
  279. # you might want to use sqrt() and pow()
  280. def getRelativePrecision(self):
  281. #the Relative precision is just ratio of 1:(total distance/LEC).
  282. #this prints something like 1:203 when we print it in the block. #this should be
  283. #just a number and no decimal.
  284. total_distance = self.getTotalDistance()
  285. linearerror = self.getLinearErrorOfClosure()
  286. relativeprecision = total_distance/linearerror
  287. return relativeprecision
  288.  
  289. # adjusts the Lot using compass rule
  290. # you might use abs(), math.degrees(), math.atan(), sqrt(), and pow()
  291. def adjustByCompassRule(self):
  292.  
  293. count = len(self.sideList)
  294.  
  295. latitude_closure = self.getLatitudeClosure()
  296. latitudes_correction = self.getLatitudeCorrectedClosure()
  297. adj_atitudeclosure = [ latitude_closure[i] + latitudes_correction[i] for i in range(count)]
  298.  
  299. departure_closure = self.getDepartureClosure()
  300. departures_correction = self.getDepartureCorrectedClosure()
  301. adj_departureclosure = [ departure_closure[i] + departures_correction[i] for i in range(count)]
  302.  
  303. adj_distance = [ math.sqrt(adj_atitudeclosure[i]*adj_atitudeclosure[i] + adj_departureclosure[i]*adj_departureclosure[i]) for i in range(count)]
  304.  
  305.  
  306. return adj_atitudeclosure, adj_departureclosure, adj_distance
  307.  
  308.  
  309.  
  310. # iterate the self.sideList
  311. # for each side object
  312. # set the departureCorrection
  313. # set the departureCorrected
  314. # and so on..
  315.  
  316. # iterate the self.sideList
  317. # for each side
  318. # set the angleCorrected of the side's Bearing
  319. # set the distanceCorrected of the side
  320.  
  321. # iterate the self.sideList
  322. # use the Lot's initialNorthing and initialEasting to set the very first endpoint
  323. # for each side
  324. # set the northing of the side's first endpoint
  325. # set the easting of the side's first endpoint
  326.  
  327. # set the northing of the side's second endpoint
  328. # set the easting of the side second endpoint
  329.  
  330. # function to compute the area using the Area by Coordinates method
  331. # it iterates through the self.sideList and gets the adjusted coordinates of the endPoints and compute the enclosed area
  332. # you might use abs() here
  333. def computeAreaByCoordinates(self):
  334.  
  335. pass
  336. class Side:
  337. def __init__(self, sideName, Bearing_bearing, double_distance):
  338. # initialize the instance variables here
  339. self.sideName = sideName
  340. self.bearing = bearing
  341. self.distance = distance
  342. # you might use the math.sin(), math.cos(), and math.radians() here
  343. # you might use the getDepartureSign() and getLatitudeSign() methods of the Bearing class
  344. # other initial processing goes here, set their initial values if possible
  345. # otherwise, set a default value
  346. self.departure = math.sin(math.radians())
  347. self.latitude = math.cos(math.radians())
  348. # this variable refer to the 2 EndPoint objects of a Side
  349. # a Tuple data structure is recommended since it has a fixed length of 2
  350. self.endPoints = 0.00
  351. self.departureCorrection = 0.00
  352. self.latitudeCorrection = 0.00
  353. self.departureCorrected = 0.00
  354. self.latitudeCorrected = 0.00
  355. self.distanceCorrected = 0.00
  356.  
  357. # declare the set and get methods of ALL the instance variables here,
  358. # especially setEndPoints() and getEndPoints()
  359.  
  360.  
  361. class Bearing:
  362. def __init__(self, angle, anglePrefix, angleSuffix):
  363.  
  364.  
  365. # check first if the input String is a valid Bearing value,
  366. # of the form 'N12-34-56W' or 'S12-34-56E'
  367. # anglePrefix is one of 'N' or 'S'
  368. # angleSuffix is one of 'E' or 'W'
  369. # initialize ALL instance variable except angleCorrected
  370. # you might use string slicing here and string's split()
  371. self.angle = angle
  372. self.angleCorrected = 0.00
  373. self.anglePrefix = anglePrefix
  374. self.angleSuffix = angleSuffix
  375.  
  376. def setAngleCorrected(self, angleCorrected):
  377. pass
  378. # GET methods for the instance variables
  379. def getAngle(self):
  380. pass
  381. def getAngleCorrected(self):
  382. pass
  383. def getAnglePrefix(self):
  384. pass
  385. def getAngleSuffix(self):
  386. pass
  387. # returns the departure sign/flag (-1 or +1) given the current Bearing's anglePrefix and angleSuffix
  388. # hint: determine the quadrant given the current Bearing's anglePrefix and angleSuffix
  389. def getDepartureSign(self):
  390. if angleSuffix.startswith("W"):
  391. return -1* departure
  392. else:
  393. return departure
  394.  
  395.  
  396.  
  397.  
  398. # returns the latitude sign/flag (-1 or +1) given the current Bearing's anglePrefix and angleSuffix
  399. # hint: determine the quadrant given the current Bearing's anglePrefix and angleSuffix
  400. def getLatitudeSign(self):
  401. if anglePrefix.startswith("S"):
  402. return -1* latitude
  403. else:
  404. return latitude
  405.  
  406. # returns the concatenated anglePrefix+<angle>+angleSuffix
  407. # <angle> is of the form DD-MM-SS
  408. # returns "N45-23-12W" for instance
  409. def bearingToString(self):
  410. pass
  411. # returns the concatenated anglePrefix+<angleCorrected>+angleSuffix
  412. # <angleCorrected> is of the form DD-MM-SS
  413. # returns the corrected "N45-23-12W" for instance
  414. def bearingCorrectedToString(self):
  415. pass
  416.  
  417.  
  418. class EndPoint:
  419. def __init__(self, endPointID):
  420. # in a given Lot's Side, say Side AB,
  421. # endPointID is either A or B
  422. # hence, one Side has 2 endPointIDs
  423. self.endPointID = endPointID
  424. # could be set to 0.00 first and then modified later
  425. # if the corrected dep and lat is known after compass rule
  426. self.northing = 0.00
  427. self.easting = 0.00
  428.  
  429. # set and get methods for ALL instance variable
  430.  
  431.  
  432. # run the main function
  433. main()
  434.  
  435. GuiFrame1().mainloop()
Advertisement
Add Comment
Please, Sign In to add comment