Advertisement
Guest User

Stata code to transform GPS to Rijksdriehoekscoordinates

a guest
May 29th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. /****************************************/
  2. /* GPS TO RIJKSDRIEHOEKSCOORDINATEN */
  3. /****************************************/
  4.  
  5. // IMPORTANT: Make sure that the variables "rijks_x" & "rijks_y" don't exist yes
  6. // Drop "rijks_x" & "rijks_y"
  7. *capture drop rijks_x
  8. *capture drop rijks_y
  9.  
  10. /****************************************/
  11. /* PART 1: CALCULATION MODULE */
  12. /****************************************/
  13.  
  14. // Program has two arguments (parameters) as input
  15. // Command syntax: <program name> <latitude to be transformed> <name of longitude variable>
  16. // Example: gps2rijks_calc_module 53.160753042 4.824761912
  17. capture program drop gps2rijks_calc_module // Check if program exists and if it does, drop it
  18. program gps2rijks_calc_module
  19. quietly {
  20. // Constants
  21. local x0 = 155000
  22. local y0 = 463000
  23. local phi0 = 52.1551729
  24. local lam0 = 5.387203657
  25.  
  26. // GPS input -> change to variable input
  27. local cord_x = `1' // test value = 53.160753042 should result in rijks_x = 117380.11
  28. local cord_y = `2' // test value = 4.824761912 should result in rijks_y = 575040.4
  29.  
  30. // Delta variables
  31. local dPhi = 0.36*(`cord_x' - `phi0')
  32. local dLam = 0.36*(`cord_y' - `lam0')
  33.  
  34. // Fill arrays with calculation parameters
  35. mata : Rp = 0,1,2,0,1,3,1,0,2
  36. mata : Rq = 1,1,1,3,0,1,3,2,3
  37. mata : Rpq = 190094.945,-11832.228,-114.221,-32.391,-0.705,-2.340,-0.608,-0.008,0.148
  38. mata : Sp = 1,0,2,1,3,0,2,1,0,1
  39. mata : Sq = 0,2,0,2,0,1,2,1,4,4
  40. mata : Spq = 309056.544,3638.893,73.077,-157.984,59.788,0.433,-6.439,-0.032,0.092,-0.054
  41.  
  42. // Initiate/reset variables for calculation loops
  43. local x = 0
  44. local y = 0
  45. local i = 1
  46. local j = 1
  47.  
  48. // Calculate X Rijksdriekhoekscoordinaat
  49. while `i' <= 9 {
  50. mata : st_local("x", strofreal(`x' + (Rpq[1,`i']) * (`dPhi')^Rp[1,`i']* (`dLam')^Rq[1,`i']))
  51. local ++i
  52. }
  53. global res_rijks_x = `x' + `x0' // Save rijksdriehoekscoordinaat x to global
  54.  
  55. // Calculate Y Rijksdriekhoekscoordinaat
  56. while `j' <= 10 {
  57. mata : st_local("y", strofreal(`y' + (Spq[1,`j']) * (`dPhi')^Sp[1,`j']* (`dLam')^Sq[1,`j']))
  58. local ++j
  59. }
  60. global res_rijks_y = `y' + `y0' // Save rijksdriehoekscoordinaat y to global
  61. }
  62. end
  63.  
  64.  
  65. /****************************************/
  66. /* PART 2: INPUT & SAVE MODULE */
  67. /****************************************/
  68.  
  69. // Program has two arguments (parameters) as input
  70. // Command syntax: <program name> <name of latitude variable> <name of longitude variable>
  71. // Example: gps2rijks latitude longitude
  72. capture program drop gps2rijks // Check if program exists and if it does, drop it
  73. program gps2rijks
  74. quietly {
  75. // Capture latitude and longitude variable names
  76. local lat = "`1'"
  77. local lon = "`2'"
  78.  
  79. // Generate empty variables
  80. gen rijks_x = .
  81. gen rijks_y = .
  82.  
  83. // Replace empty variable values with the calculated Rijksdriehoekscoordinaten
  84. local i = 1
  85. while `i' <= _N {
  86. gps2rijks_calc_module `lat'[`i'] `lon'[`i'] // Call calculation module with GPS coordinates of the i'th observation
  87. replace rijks_x = $res_rijks_x if _n == `i'
  88. replace rijks_y = $res_rijks_y if _n == `i'
  89. local `++i'
  90. }
  91. }
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement