// longitude0, latitude0, parallel1, parallel2 public AlbersEqualAreaProjection(IDictionary <string, double> parameters) : base(parameters) { var latitude0Rad = InputLatitude("latitude0"); var parallel1Rad = InputLatitude("parallel1"); var parallel2Rad = InputLatitude("parallel2"); var cosParallel1 = Math.Cos(parallel1Rad); var sinParallel1 = Math.Sin(parallel1Rad); _n2 = sinParallel1 + Math.Sin(parallel2Rad); if (Math.Abs(_n2) <= MathX.Tolerance) { throw new ArgumentOutOfRangeException(); } _n = _n2 / 2; _nHalf = _n2 / 4; var invN2 = 1 / _n2; _invN = 2 / _n2; _c = MathX.Square(cosParallel1) + sinParallel1 * _n2; _cOverN2 = _c * invN2; var a = _c - Math.Sin(latitude0Rad) * _n2; if (a < 0) { throw new ArgumentOutOfRangeException(); } _ro0 = Math.Sqrt(a) * _invN; }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { var ro = Math.Sign(_n) * Math.Sqrt(x * x + MathX.Square(_ro0 - y)); // If ro is zero or very small then latitude will be +-Pi/2 depending on the sign of f. latitude = 2 * Math.Atan(Math.Pow(_f / ro, _nInv)) - Math.PI / 2; longitude = MathX.Clamp(Math.PI, Math.Atan2(x, _ro0 - y) * _nInv); }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { var ros = x * x + (_ro0 - y) * (_ro0 - y); var a = _cOverN2 - ros * _nHalf; if (double.IsNaN(a) || Math.Abs(a) > 1 + MathX.Tolerance) { throw new ArgumentOutOfRangeException(paramName: string.Join(",", new [] { nameof(x), nameof(y) })); } latitude = Math.Asin(MathX.Clamp(1, a)); longitude = MathX.Clamp(Math.PI, MathX.Atan2(x, _ro0 - y, "x, y") * _invN); }
protected internal override void Project(double latitude, double longitude, out double x, out double y) { var sinLatitude = Math.Sin(latitude); var cosLatitude = Math.Cos(latitude); var sinLongitude = Math.Sin(longitude); var cosLongitude = Math.Cos(longitude); var a = _sinFiP * sinLatitude - _cosFiP * cosLatitude * sinLongitude; // sin_fi_p if (double.IsNaN(a) || Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException(string.Join(",", new[] { nameof(latitude), nameof(longitude) })); } x = MathX.Atan2(sinLatitude / cosLatitude * _cosFiP + sinLongitude * _sinFiP, cosLongitude, "latitude, longitude"); y = MathX.Clamp(MaxY, Math.Log((1 + a) / (1 - a)) / 2); // protect against +-Infinity }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { var sinX = Math.Sin(x); var cosX = Math.Cos(x); var sinhY = Math.Sinh(y); var coshY = Math.Cosh(y); // cosh_y >= 1 by definition var a = (_sinFiP * sinhY + _cosFiP * sinX) / coshY; if (Math.Abs(a) > 1) { throw new ArgumentOutOfRangeException(string.Join(",", new [] { nameof(x), nameof(y) })); } latitude = Math.Asin(a); longitude = MathX.Atan2(_sinFiP * sinX - _cosFiP * sinhY, cosX, "x, y"); }
protected internal override void Unproject(double x, double y, out double latitude, out double longitude) { if (x >= MaxX) { latitude = 0; longitude = Math.PI / 2; } else if (x <= -MaxX) { latitude = 0; longitude = -Math.PI / 2; } else { // 1 <= cosh(x) <= cosh(MaxX) latitude = Math.Asin(Math.Sin(y) / Math.Cosh(x)); // In case of x=0 and y=+-Pi/2: latitude will be +-90 and longitude will be 0 longitude = MathX.Atan2(Math.Sinh(x), Math.Cos(y)); } }
// x will be in range [-MaxX, MaxX] // y will be in range [-Pi, Pi] protected internal override void Project(double latitude, double longitude, out double x, out double y) { // North pole if (latitude >= Math.PI / 2 - MathX.Tolerance) { x = 0; y = Math.PI / 2; return; } // South pole if (latitude <= -Math.PI / 2 + MathX.Tolerance) { x = 0; y = -Math.PI / 2; return; } if (Math.Abs(latitude) <= MathX.Tolerance) { // East of India if (Math.Abs(longitude - Math.PI / 2) <= MathX.Tolerance) { x = MaxX; y = 0; return; } // West of South America if (Math.Abs(longitude + Math.PI / 2) <= MathX.Tolerance) { x = -MaxX; y = 0; return; } } double b = Math.Cos(latitude) * Math.Sin(longitude); x = MathX.Clamp(MaxX, Math.Log((1 + b) / (1 - b)) / 2); y = Math.Atan2(Math.Tan(latitude), Math.Cos(longitude)); }
protected internal double InputLongitude(string name, double max) { return(MathX.InputLong(_parameters[name], max, name)); }
protected internal override void Project(double latitude, double longitude, out double x, out double y) { x = longitude; y = MathX.Clamp(_maxY, Math.Log(Math.Tan(Math.PI / 4 + latitude / 2))); // protect against +-Infinity }