Advertisement
Hellerick_Ferlibay

GPLK map projection

Sep 27th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.82 KB | None | 0 0
  1. import math
  2.  
  3. pi=3.14159265358979
  4. degrees=pi/180
  5.  
  6. ############################ ENTER DATA ############################
  7. mapin=open('J:\EX-IM\W2H\Map projection\Atlas_of_of_Venus_(Venusian_Haven).V1.svg', 'rb')
  8. mapout=open('J:\EX-IM\W2H\Map projection\Atlas_of_of_Venus_(Venusian_Haven).EasternHemisphere.svg', 'wb')
  9. C5=-6*degrees # Point A longitude
  10. C6=0*degrees # Point A latitude
  11. D5=173*degrees # Point B longitude
  12. D6=-0*degrees # Point B latitude
  13. C13=0 # 1 for Lambert azimuthal, 0 for Gall-Peters cilindric
  14. ####################################################################
  15.  
  16. l4c="1234" # the last four characters
  17. readcoordinates=False
  18. watchit=False
  19. numberstatus=0  # 0: not within a coordinate pair
  20.                 # 1: read the first number
  21.                 # 2: between the two coordinates
  22.                 # 3: read the second number
  23. num1=''
  24. num2=''
  25. numchars=['0','1','2','3','4','5','6','7','8','9','.','-','+','e']
  26.  
  27. def roundit(sn=3.14159265358979):
  28.     rnum=round(sn,5) # the number stands for the number of digits after the point
  29.     position=`sn`.find('.')
  30.     snum=`sn`[:position+6]
  31.     return snum
  32.  
  33. C7=math.cos(C5)*math.cos(C6)
  34. C8=math.sin(C5)*math.cos(C6)
  35. C9=math.sin(C6)
  36. D7=math.cos(D5)*math.cos(D6)
  37. D8=math.sin(D5)*math.cos(D6)
  38. D9=math.sin(D6)
  39. E7=(C7+D7)/2
  40. E8=(C8+D8)/2
  41. E9=(C9+D9)/2
  42. E10=math.sqrt(E7*E7+E8*E8+E9*E9)
  43. F7=E7/E10
  44. F8=E8/E10
  45. F9=E9/E10
  46. F5=math.atan2(F8,F7)
  47. F6=math.asin(F9)
  48.  
  49. G3=math.cos(F5)*math.cos(F6)
  50. G4=math.sin(F5)*math.cos(F6)
  51. G5=math.sin(F6)
  52. H3=-math.sin(F5)
  53. H4=math.cos(F5)
  54. H5=0
  55. I3=-math.sin(F6)*math.cos(F5)
  56. I4=-math.sin(F6)*math.sin(F5)
  57. I5=math.cos(F6)
  58.  
  59. D16=C5
  60. E16=C6
  61. F16=math.cos(D16)*math.cos(E16)
  62. G16=math.sin(D16)*math.cos(E16)
  63. H16=math.sin(E16)
  64. I16=F16*H4*I5+G16*H5*I3+H16*H3*I4-H16*H4*I3-H5*I4*F16-I5*G16*H3
  65. J16=G3*G16*I5+G4*H16*I3+G5*F16*I4-G5*G16*I3-H16*I4*G3-I5*G4*F16
  66. K16=G3*H4*H16+G4*H5*F16+G5*H3*G16-G5*H4*F16-H5*G16*G3-H16*G4*H3
  67. L16=math.atan2(J16,I16)
  68. M16=math.asin(K16)
  69. P16=-math.atan2(J16,K16)*1-pi/2
  70.  
  71. G7=math.cos(F5)*math.cos(F6)
  72. G8=math.sin(F5)*math.cos(F6)
  73. G9=math.sin(F6)
  74. H7=math.cos(P16)*H3+math.sin(P16)*I3
  75. H8=math.cos(P16)*H4+math.sin(P16)*I4
  76. H9=math.cos(P16)*H5+math.sin(P16)*I5
  77. I7=math.cos(P16)*I3-math.sin(P16)*H3
  78. I8=math.cos(P16)*I4-math.sin(P16)*H4
  79. I9=math.cos(P16)*I5-math.sin(P16)*H5
  80.  
  81. def calculatecoordinates(D20,E20):
  82.     F20=math.cos(D20)*math.cos(E20)
  83.     G20=math.sin(D20)*math.cos(E20)
  84.     H20=math.sin(E20)
  85.     I20=F20*H8*I9+G20*H9*I7+H20*H7*I8-H20*H8*I7-H9*I8*F20-I9*G20*H7
  86.     J20=G7*G20*I9+G8*H20*I7+G9*F20*I8-G9*G20*I7-H20*I8*G7-I9*G8*F20
  87.     K20=G7*H8*H20+G8*H9*F20+G9*H7*G20-G9*H8*F20-H9*G20*G7-H20*G8*H7
  88.     L20=math.atan2(J20,I20)
  89.     M20=math.asin(K20)
  90.     N20=L20
  91.     O20=math.sin(M20)
  92.     P20=math.atan2(J20,K20)
  93.     Q20=math.sqrt(J20*J20+K20*K20+(1-I20)*(1-I20))
  94.     R20=math.sin(P20)*Q20
  95.     S20=math.cos(P20)*Q20
  96.     T20=R20*C13+N20*(1-C13)
  97.     U20=S20*C13+O20*(1-C13)
  98.     W20=T20/degrees
  99.     X20=U20/degrees
  100.     Z20=math.atan2(X20,W20)+P16
  101.     AA20=math.sqrt(W20*W20+X20*X20)
  102.     AC20=math.cos(Z20)*AA20
  103.     AD20=-math.sin(Z20)*AA20
  104.     if watchit:
  105.         print 'num1', num1
  106.         print 'num2', num2
  107.         print D20
  108.         print E20
  109.         print F20
  110.         print G20
  111.         print H20
  112.         print I20
  113.         print J20
  114.         print K20
  115.         print L20
  116.         print M20
  117.         print N20
  118.         print O20
  119.         print P20
  120.         print Q20
  121.         print R20
  122.         print S20
  123.         print T20
  124.         print U20
  125.         print W20
  126.         print X20
  127.         print Z20
  128.         print AA20
  129.         print AC20
  130.         print AD20
  131.     mapout.write(roundit(AC20)+","+roundit(AD20))
  132.  
  133. while True:
  134.     try:
  135.         ch=mapin.read(1)
  136.         if ch=='': break
  137.         if ch=='$': watchit=True
  138.         l4c=l4c[1:]+ch
  139.         if readcoordinates and (ch=='"'):
  140.             readcoordinates=False
  141.             if (l4c[2] in numchars) and (numberstatus==3):
  142.                 numberstatus=0
  143.                 calculatecoordinates((eval(num1)-180.0)*pi/180,(90.0-eval(num2))*pi/180)
  144.                 num1=""
  145.                 num2=""
  146.         if l4c==' d="': readcoordinates=True
  147.         if readcoordinates:
  148.             if (numberstatus==0) and (ch in numchars): numberstatus=1
  149.             if (numberstatus==1) and (not (ch in numchars)): numberstatus=2
  150.             if (numberstatus==2) and (ch in numchars): numberstatus=3
  151.             if (numberstatus==3) and (not (ch in numchars)):
  152.                 numberstatus=0
  153.                 calculatecoordinates((eval(num1)-180.0)*pi/180,(90.0-eval(num2))*pi/180)
  154.                 num1=""
  155.                 num2=""
  156.             if numberstatus==1: num1=num1+ch
  157.             if numberstatus==3: num2=num2+ch
  158.             if numberstatus==0: mapout.write(ch)
  159.         else:
  160.             mapout.write(ch)
  161.     except KeyboardInterrupt: break
  162.  
  163. mapout.close()
  164. mapin.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement