toLatLong method

dynamic toLatLong(
  1. dynamic datum
)

Converts the cartesian coordinate to latitude and longitude using a given ellipsoid

Implementation

toLatLong(var datum) {
  final ellipsoid = ellipsoids[datum["ellipsoid"]];
  final a = ellipsoid!["a"]!;
  final b = ellipsoid["b"]!;
  final f = ellipsoid["f"]!;

  final e2 = 2*f - f*f; //1st eccentricity
  final E2 = e2 / (1-e2); //2nd eccentricity
  final p = math.sqrt(x*x + y*y); //distance from minor axis
  final R = math.sqrt(p*p + z*z); //polar radius

  //parametric latitude
  final tanB = (b*z)/(a*p) * (1+E2*b/R);
  final sinB = tanB / math.sqrt(1+tanB*tanB);
  final cosB = sinB / tanB;

  //geodetic latitude
  final double w = cosB.isNaN ? 0 : math.atan2(z + E2*b*sinB*sinB*sinB, p - e2*a*cosB*cosB*cosB);

  //longitude
  final l = math.atan2(y, x);

  //height above ellipsoid
  final sinw = math.sin(w);
  final cosw = math.cos(w);
  final v = a / math.sqrt(1-e2*sinw*sinw);
  final h = p*cosw + z*sinw - (a*a/v);

  final point = new LatLong(degrees(w), degrees(l), h, datum);
  return point;
}