|
1 | 1 | .. _tutorials/transform: |
2 | 2 |
|
3 | 3 | Datum Transformation |
4 | | -===================== |
| 4 | +===================== |
| 5 | + |
| 6 | +GeodePy has the ability to tranform between datums. Here we will discuss how to |
| 7 | +change between datums without changing the reference epoch while in the |
| 8 | +:ref:`time dependant <tutorials/timetrans>` tutorial we will discuss changing epochs. |
| 9 | + |
| 10 | +Common Example |
| 11 | +-------------- |
| 12 | + |
| 13 | +The most common example for datum transformation is converting from MGA94 to MGA2020. |
| 14 | +This is handled by a function in the transformation module that converts the input to |
| 15 | +grid input to caresian coordinate (xyz), and then runs a 7 paramter helmert transformation |
| 16 | +using the GDA94_to_gda2020 transformation constant. This process will be explored more in |
| 17 | +the :ref:`latter <tutorials/transformfunc>` part of this tutorial but first lets use this function. |
| 18 | + |
| 19 | +Begin by importing GeodePy: |
| 20 | + |
| 21 | +.. code:: python |
| 22 | +
|
| 23 | + import geodepy.transform |
| 24 | +
|
| 25 | +Next, define some coordinate values in MGA94: |
| 26 | + |
| 27 | +.. code:: python |
| 28 | +
|
| 29 | + zone_94 = 55 |
| 30 | + east_94 = 696053.3373 |
| 31 | + north_94 = 6086610.1338 |
| 32 | +
|
| 33 | +Now, transform this coordinate to MGA2020: |
| 34 | + |
| 35 | +.. code:: python |
| 36 | +
|
| 37 | + (zone_20, east_20, north_20, _, _) = geodepy.transform.transform_mga94_to_mga2020( |
| 38 | + zone_94, |
| 39 | + east_94, |
| 40 | + north_94 |
| 41 | + ) |
| 42 | +
|
| 43 | +Finally, print the transformed coordinate: |
| 44 | + |
| 45 | +.. code:: python |
| 46 | +
|
| 47 | + print(zone_20, east_20, north_20) |
| 48 | +
|
| 49 | +This will output the zone, easting and northing of the coordinate in MGA2020. |
| 50 | + |
| 51 | +.. code:: |
| 52 | +
|
| 53 | + >> 55 696053.872 6086611.549 |
| 54 | +
|
| 55 | +In this transformation you can see that a function from the transformation module was used. |
| 56 | + |
| 57 | +.. _tutorials/transformfunc: |
| 58 | + |
| 59 | +Constructing a new Transformation Function |
| 60 | +------------------------------------------ |
| 61 | + |
| 62 | +Here we will explore how to complete a transformation between datums without a dedicated function. |
| 63 | +We will then create a new function for this new transformation. Here we are going to transform between agd84 to gda2020 |
| 64 | + |
| 65 | +First import GeodePy. |
| 66 | + |
| 67 | +.. code:: python |
| 68 | +
|
| 69 | + import geodepy.transform |
| 70 | + import geodepy.constants |
| 71 | + import geodepy.angles |
| 72 | +
|
| 73 | +Now we need some starting coordinates |
| 74 | + |
| 75 | +.. code:: python |
| 76 | +
|
| 77 | + lat = geodepy.angles.DMSAngle(-23,33,25.21) |
| 78 | + long = geodepy.angles.DMSAngle(133,49,13.87) |
| 79 | + height = 427.863 |
| 80 | +
|
| 81 | + print(f"The AGD84 position is {lat}, {long}, {height}" |
| 82 | +
|
| 83 | + >>The AGD84 position is -23 33 25.21, 133 49 13.87, 427.863 |
| 84 | +
|
| 85 | +All transformations in GeodePy need to be completed with corrdinates in cartesian (xyz) form. Lets transform to xyz. |
| 86 | +
|
| 87 | +.. code:: python |
| 88 | +
|
| 89 | + x, y, z = geodepy.transform.llh2xyz(lat, long, height) |
| 90 | + print(x, y, z) |
| 91 | +
|
| 92 | + >>-4050634.051819 4220935.13646 -2533555.369303 |
| 93 | +
|
| 94 | +Now the transformation parameters need to be entered. Within Geodepy there are many transformaton parameters already |
| 95 | +entered within the constants module. A table of these can be seen :ref:`here <features/constants/transform>`. If the |
| 96 | +transformation needed isn't currently in Geodepy, new transofmrations can be added using the :ref:`transformation class <transclass>`. |
| 97 | +Here the agd66_to_gda94 transformation will be used. |
| 98 | +
|
| 99 | +.. code:: python |
| 100 | +
|
| 101 | + print(geodepy.constants.agd84_to_gda94) |
| 102 | +
|
| 103 | + >>Transformation: From 'AGD84' to 'GDA94' |
| 104 | + >>Reference Epoch: 0 |
| 105 | + >>tx: -117.763m + 0.0m/yr |
| 106 | + >>ty: -51.51m + 0.0m/yr |
| 107 | + >>tz: 139.061m + 0.0m/yr |
| 108 | + >>sc: -0.191ppm + 0.0ppm/yr |
| 109 | + >>rx: -0.292" + 0.0"/yr |
| 110 | + >>ry: -0.443" + 0.0"/yr |
| 111 | + >>rz: -0.277" + 0.0"/yr |
| 112 | +
|
| 113 | +Now this will be used to complete a 7 paramter helmert transformation. |
| 114 | +
|
| 115 | +.. code:: python |
| 116 | +
|
| 117 | + x_94, y_94, z_94, _ = geodepy.transform.conform7(x, y, z, geodepy.constants.agd84_to_gda94) |
| 118 | + print(x_94, y_94, z_94) |
| 119 | +
|
| 120 | + >>-4050762.150962 4220880.96717 -2533401.14935 |
| 121 | +
|
| 122 | +.. tip:: |
| 123 | + The "_" in the conform7 variables is for a vcv matrix. If you dont input a vcv matrix |
| 124 | + then the resulting variable will be None. However as the variable needs to be assigned |
| 125 | + for the function to work using "_" meets to requirement but doesn't store the variable |
| 126 | + in a meaningful way. |
| 127 | +
|
| 128 | +Now we need to transform from GDA94 to GDA2020 using the same method but with the gda94_to_gda2020 |
| 129 | +transformation class. |
| 130 | +
|
| 131 | +.. code:: python |
| 132 | +
|
| 133 | + x_20, y_20, z_20, _ = geodepy.transform.conform7(x_94, y_94, z_94, geodepy.constants.gda94_to_gda2020) |
| 134 | +
|
| 135 | + print(x_20, y_20, z_20) |
| 136 | +
|
| 137 | + >>-4050763.124034 4220880.75310 -2533399.713463 |
| 138 | +
|
| 139 | +Now the cartesian coordinates can be converted back to geographic coordinates (lat, long) |
| 140 | +
|
| 141 | +.. code:: python |
| 142 | +
|
| 143 | + lat_20, long_20, height_20 = geodepy.transform.xyz2llh(x_20, y_20, z_20) |
| 144 | +
|
| 145 | + print(f"The GDA2020 position is {geodepy.angles.dec2dms(lat_20)}, {geodepy.angles.dec2dms(long_20)}, {height_20}") |
| 146 | +
|
| 147 | + >>The GDA2020 position is -23 33 19.921108332, 133 49 18.481110119, 411.61055134 |
| 148 | +
|
| 149 | +All of this can now be combined into one function. |
| 150 | +
|
| 151 | +.. code:: python |
| 152 | +
|
| 153 | + def transform_agd84_to_gda2020(lat, long, height): |
| 154 | +
|
| 155 | + x, y, z = geodepy.transform.llh2xyz(lat, long, height) |
| 156 | + x_94, y_94, z_94, _ = geodepy.transform.conform7(x, y, z, geodepy.constants.agd84_to_gda94) |
| 157 | + x_20, y_20, z_20, _ = geodepy.transform.conform7(x_94, y_94, z_94, geodepy.constants.gda94_to_gda2020) |
| 158 | +
|
| 159 | + return geodepy.transform.xyz2llh(x_20, y_20, z_20) |
| 160 | +
|
| 161 | + lat_new, long_new, height_new = transform_agd84_to_gda2020(lat, long, height) |
| 162 | +
|
| 163 | + print(f"The GDA2020 position is {geodepy.angles.dec2dms(lat_new)}, {geodepy.angles.dec2dms(long_new)}, {height_new}") |
| 164 | +
|
| 165 | + >>The GDA2020 position is -23 33 19.921108332, 133 49 18.481110119, 411.61055134 |
| 166 | +
|
0 commit comments