Tuesday, August 7, 2012

Transformation between datum's in JavaScript – Part 1


1.     Introduction


In part 1 of a two parts article I will outline the architecture involved in the transformation of projected coordinate  systems. In the second part  a detailed explanation will be done with the transformation between the projected coordinate  system WGS 84 and the projected coordinate  system Belgium Lambert 72 (ESPG 31370). Not all of the formulas showed here are generic for all local (country) projected coordinate  systems, however the same steps has to been implemented for other transformations.
In the JavaScript framework for ArcGIS JavaScript API  I added the possibility for adding Google Places to a map using the Google API. All locations retrieved have  WGS 84 coordinates. In case the spatial reference of the base map is not a WGS 84 (geographic or web Mercator ) projection a transformation is required for adding points representing the Google locations to the map.
The idea for implementation a projection transformation in JavaScript  comes from the problems when using the project method of the geometry rest service.  As from 10.1 the project method of the geometry rest service now supports the use of a transformation parameter.  However when using the rest service for doing transformation between WGS 84 and Belgium Lambert 72, I encountered the following issues:
·         Using 20 points (number of locations returned from Google API) returns an error in the rest service. This could be a problem caused by the proxy service. So I had to split the result from the Google API into two parts. Because using the Google maps API is asynchronous, the handling of results makes it more tricky. Adding to that is also the use of a token to be able to retrieve the next trunk of 20 results of the Google places API until a maximum of 60 locations have been retrieved.

·         The transformation from WGS84 to Belgian Lambert 72 gives me an error of around 200m. I suspect that not the full datum transformation is used. 

Strange enough the transformation from Belgium Lambert 72 to WGS 84 works correct.

2.     Different transformation situations


The transformation between projections consists of different situations depends on the input  projection in geographic or Cartesian coordinates  and the output  projection  in geographic or Cartesian coordinates . The following  pictures illustrates the different situations. Later I illustrate through examples each of the different steps.
The most complex situation is when input  is a projected coordinate system and output a projected coordinate system are in Cartesian coordinates.

A less complex situation is when the input is a geographic coordinate system and output is a projected coordinate system. This is the case when WGS84 geographic coordinates are involved.  For the transformation from WGS 84 to Belgium Lambert 72 this is the steps that are needed to transform coordinates from WGS84 degrees to Lambert 72 x and y expressed in meters.

A much simpler transformation is the situation when you need to transform between two geographic coordinate systems. Here only one step is required.


Other possibilities are showed in the next pictures. I will not handle this kind of transformation.



3.     Steps involved in transformations


In this section I show an overview of the different steps involved in the transformation between two coordinate systems. There exists interested literature on all this individual steps. In the section bibliography at the end of this expose some important url ‘s are listed. In the figure hereafter you can see the classification of the different methods that we need to implement in JavaScript  to complete a transformation between two projected coordinate systems.


3.1 Inverse mapping


This step is responsible for the transformation of Cartesian coordinates x , y expressed in distances (meters, feeds) to geographic coordinates latitude and longitude  φ ,λ expressed in degrees. Transformations needed here depends on the local (country) projected coordinate system.

3.2 Forward mapping


This step is responsible for the transformation of geographic coordinates latitude and longitude  φ ,λ expressed in degrees  to Cartesian coordinates x , y expressed in distances (meters, feeds) . Transformations needed here depends on the local (country) projected coordinate system.

3.3 Geographic coordinates to geocentric coordinates translation


To be able to transform coordinates from one ellipsoid to another ellipsoid, coordinates must be expressed into geocentric coordinates relative to the center of the ellipsoid. In a projected coordinate system, an ellipsoid is always specified. This formula is geographic or projected coordinate system not depended.  Different parameters that define an ellipsoid are used to calculate the x, y and z in meters.

3.4 Geocentric coordinates to geographic coordinates  translation


As with the translation explained in 3.3, the formula for geocentric to geographic coordinates does not depends on the coordinate system involved. The same set of parameters for the ellipsoid is used in the formula.

3.5 Geocentric  transformations


Transformations between coordinate systems has been defined through the Helmert 7 parameters or the Molodensky -Badekas 10 parameter. In case of the transformation for WGS 84 geographic coordinate system to Lambert 72 projected coordinate system the Helmert 7 parameter transformation is used and will be illustrated. Implementing the Molodensky –Badekas transformation is not much deferent than the Helmert 7 version.

4.     Parameters required


In order to do the transformation a number of parameter values are needed. These parameters depends on the ellipsoids involved and the projection transformation required. Because some methods required special parameters depending on the local (country) projected system used,  the transformation between WGS84 to Belgium Lambert 72 is not generic. Also some methods in the transformation process are local depended. Still the procedure illustrated gives You an idea how this can be extended to support other projected systems. One document is very important to help you choose the correct formulas and can be found in the bibliography.
The ellipsoid is defined through the parameters showed hereafter as an example. A more complete list can be found in the bibliography.

a             Semi-Major Axis (Equatorial Radius)

b             Semi-Minor Axis (Polar Radius)

f              Flattening = (a-b)/a

e             First Eccentricity = sqrt(1-(b²/a²))

Constants for Reference Ellipsoids used for Datum Transformations
Ellipsoid
(a)
(b)
f
e
GRS 80
6378137
6356752.3141
0.0033528106875095227
0.08181919111988833
INTERNATIONAL 1924
6378388
6356911.946
0.003367003387062615
0.0819918902228546
WGS 84
6378137
6356752.3142
0.0033528106718309896
0.08181919092890624
AUSTRALIAN 1965
6378160
6356774.719
0.003352891899858333
0.08182018036905428

Another table required is the Helmert 7 parameters defined for a transformation between two Cartesian coordinates systems. At the website of Esri you can find a list of transformations, most are between WGS 84 or ETRS 1989 and a local projected coordinate system.

Geographic (datum) Transformation Name
WKID
dx
dy
dz
rx
ry
rz
ds
Belge_1972_To_WGS_1984_3
15929
-106.868628
52.297783
-103.723893
-0.33657
0.456955
-1.842183
-1.2747










5.     Bibliography


List of all ellipsoids used in projected coordinate systems together with the parameters that define the ellipsoid.
List of the transformations as has been defined by ESRI Inc. Most important are the Helmert 7 parameter table and the Molodensky –Badekas 10 parameter table.
I consider this document as the bible of the transformations between projected coordinate systems. You will find all the different formulas that you will need explained in detail. It is not an easy reading for a developer, but it is an absolute must when you want to create a transformation in code yourself.  The document also includes examples of input and output, making it much easier to create unit testing for your code. Other interesting documents at this site is G7-1.pdf.
For those who likes some didactical material, this site from the Dutch ITC Faculty of Geo-Information Science and Earth Observation of the University of Twente gives a very readable explanation of transformation of projected coordinate systems.  A must if you want more about different projections and transformations.
Another educational tutorial about transformation between coordinate systems illustrated with ArcGIS desk products of ESRI Inc.
Some useful tools:
Sometimes you will need a translation between degrees and radians. This web site is an excellent tool for doing the conversion of degrees, minutes and seconds into a decimal degrees and radians.
For the Belgian developer
At the site of http://www.ngi.be you can find a tool called cConvert. This is a great tool when doing transformations between WGS 84 projected coordinate systems and Belgian projected coordinate systems. It helped me a lot to see at what level of accuracy the JavaScript transformation method works. The tool also allow to see the effects of adding a correction for the scale distortion.  It was not needed in the transformation to Lambert 72 to include this type of correction because with the regular formulas I had already an accuracy around 10 centimeters.





1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..
    I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai .
    or Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

    ReplyDelete