How To Convert Angles From Decimal Degrees To DMS In Python

Angular measurements are very important aspects of any mathematical computations especially for the Geomatic Engineers.


There are two main types of forms of angular measurements used, that is Decimal Degrees and Degrees Minutes and Seconds (DMS).


Therefore converting from one form to the other form occurs very regularly, in view of this, knowledge in programming language called python could be used to design a program which can do that automatically for us without having to do that by ourselves all the time.

The following are the source codes

#The program has two functions
#converting from Decimal Degrees(DD) to Degrees, Minutes and seconds(DMS)
#Converting from DMS to DD
#programmer: Bra Brainy

print('choose an activity to perform')
print('1.Convert from Degrees Minutes and Seconds to Decimal Degrees')
print('2.Convert from Decimal Degrees to Degrees,Minutes and Seconds')
Choice = int(input('Choose what you want to do!:\n')) #choose what you want to do
if Choice==1:
print('Welcome buddy!')
print('Enter the value of what you want to convert by following the program')
print() #print nothing in this line
Degrees = int(input('enter the degrees value:\n')) #enter the value here
Minutes = int(input('enter the minutes value:\n')) #enter the value
Seconds = int(input('enter the seconds value:\n')) #enter the value
print()
DD = round((Degrees+(Minutes/60)+(Seconds/3600)),3)#formular for the conversion
print('The answer in Decimal Degrees is: ', DD)

elif Choice==2:
DecimalDegree = float(input('enter the value in decimal degrees:\n'))
Degrees = int(DecimalDegree) #stores only the integer part
Minutes = int((DecimalDegree-Degrees)*60) # multiply the decimal part by 60 and store the integer part
Seconds = round(((((DecimalDegree-Degrees)*60)-Minutes)*60)) #multiply the decimal part of the minute 60 and round it to nearest integer
DegMinSec = print('Your answer in Degress,minutes and seconds is: ',Degrees,'°',Minutes,'\'',Seconds,'"')#print out the final results

No comments:

Post a Comment