Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LambertConformalProjection
- {
- private double n;
- private double F;
- private double rho;
- private double earthRadiusTimesF;
- private double lon0Degrees;
- private double lat0;
- private double lon0;
- private double par1;
- private double par2;
- private double falseEasting;
- private double falseNorthing;
- public LambertConformalProjection(double centerPtLat, double standardLon, double trueLat1, double trueLat2)
- : this(centerPtLat, standardLon, trueLat1, trueLat2, 0.0D, 0.0D)
- {
- }
- public LambertConformalProjection(double centerPtLat, double standardLon, double trueLat1, double trueLat2, double falseEast, double falseNorth)
- {
- this.lat0 = this.ToRadians(centerPtLat);
- this.lon0 = this.ToRadians(standardLon);
- this.par1 = trueLat1;
- this.par2 = trueLat2;
- double d = 1.0D;
- if (Double.IsNaN(falseEast))
- {
- falseEast = 0.0D;
- }
- if (Double.IsNaN(falseNorth))
- {
- falseNorth = 0.0D;
- }
- int i = (falseEast != 0.0D) || (falseNorth != 0.0D) ? 1 : 0;
- if (i != 0)
- {
- d = 1.0D;
- }
- this.falseEasting = (d * falseEast);
- this.falseNorthing = (d * falseNorth);
- this.Precalculate();
- }
- private double ToRadians(double degrees)
- {
- return degrees * Math.PI / 180.0;
- }
- private double ToDegrees(double radians)
- {
- return radians * 180.0 / Math.PI;
- }
- private void Precalculate()
- {
- if (Math.Abs(this.lat0 - 1.570796326794897D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal lat0 = 90");
- }
- if (Math.Abs(this.lat0 + 1.570796326794897D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal lat0 = -90");
- }
- if (Math.Abs(this.par1 - 90.0D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal par1 = 90");
- }
- if (Math.Abs(this.par1 + 90.0D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal par1 = -90");
- }
- if (Math.Abs(this.par2 - 90.0D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal par2 = 90");
- }
- if (Math.Abs(this.par2 + 90.0D) < 1.0E-006D)
- {
- throw new ArgumentException("LambertConformal par2 = -90");
- }
- double d1 = this.ToRadians(this.par1);
- double d2 = this.ToRadians(this.par2);
- double d3 = Math.Tan(0.7853981633974483D + d1 / 2.0D);
- double d4 = Math.Tan(0.7853981633974483D + d2 / 2.0D);
- if (Math.Abs(this.par2 - this.par1) < 1.0E-006D)
- {
- this.n = Math.Sin(d1);
- }
- else
- {
- this.n = (Math.Log(Math.Cos(d1) / Math.Cos(d2)) / Math.Log(d4 / d3));
- }
- double d5 = Math.Pow(d3, this.n);
- this.F = (Math.Cos(d1) * d5 / this.n);
- this.earthRadiusTimesF = (6371.2290000000003D * this.F) * 1000;
- double d6 = Math.Pow(Math.Tan(0.7853981633974483D + this.lat0 / 2.0D), this.n);
- this.rho = (6371.2290000000003D * 1000 * this.F / d6);
- this.lon0Degrees = this.ToDegrees(this.lon0);
- }
- public void LatLonToProj(double[] inLonLatOutXY)
- {
- var xy = this.LatLonToProj(new CoordinateLatLon() { Lon = inLonLatOutXY[0], Lat = inLonLatOutXY[1] });
- inLonLatOutXY[0] = xy.X;
- inLonLatOutXY[1] = xy.Y;
- }
- public CoordinateXY LatLonToProj(double paramDouble1, double paramDouble2, CoordinateXY paramCoordinateXY)
- {
- double d3 = paramDouble1;
- double d4 = paramDouble2;
- d3 = this.ToRadians(d3);
- double d5 = CoordinateLatLon.LonNormal(d4 - this.lon0Degrees);
- double d6 = this.n * this.ToRadians(d5);
- double d7 = Math.Pow(Math.Tan(0.7853981633974483D + d3 / 2.0D), this.n);
- double d8 = this.earthRadiusTimesF / d7;
- double d1 = d8 * Math.Sin(d6);
- double d2 = this.rho - d8 * Math.Cos(d6);
- paramCoordinateXY.X = ((float)(d1 + this.falseEasting));
- paramCoordinateXY.Y = ((float)(d2 + this.falseNorthing));
- return paramCoordinateXY;
- }
- public CoordinateXY LatLonToProj(CoordinateLatLon paramCoordinateLatLon)
- {
- double d3 = paramCoordinateLatLon.Lat;
- double d4 = paramCoordinateLatLon.Lon;
- d3 = this.ToRadians(d3);
- double d5 = CoordinateLatLon.LonNormal(d4 - this.lon0Degrees);
- double d6 = this.n * this.ToRadians(d5);
- double d7 = Math.Pow(Math.Tan(0.7853981633974483D + d3 / 2.0D), this.n);
- double d8 = this.earthRadiusTimesF / d7;
- double d1 = d8 * Math.Sin(d6);
- double d2 = this.rho - d8 * Math.Cos(d6);
- return new CoordinateXY() { X = (d1 + this.falseEasting), Y = (d2 + this.falseNorthing) };
- }
- public CoordinateLatLon ProjToLatLon(CoordinateXY paramCoordinateXY)
- {
- CoordinateLatLon localCoordinateLatLon = new CoordinateLatLon();
- return ProjToLatLon(localCoordinateLatLon, paramCoordinateXY.X, paramCoordinateXY.Y);
- }
- public CoordinateLatLon ProjToLatLon(CoordinateLatLon paramCoordinateLatLon, double paramFloat1, double paramFloat2)
- {
- double d3 = paramFloat1 - this.falseEasting;
- double d4 = paramFloat2 - this.falseNorthing;
- double d5 = this.rho;
- if (this.n < 0.0D)
- {
- d5 *= -1.0D;
- d3 *= -1.0D;
- d4 *= -1.0D;
- }
- double d6 = d5 - d4;
- double d7 = Math.Atan2(d3, d6);
- double d8 = Math.Sqrt(d3 * d3 + d6 * d6);
- if (this.n < 0.0D)
- {
- d8 *= -1.0D;
- }
- double d2 = this.ToDegrees(d7 / this.n + this.lon0);
- double d1;
- if (Math.Abs(d8) < 1.0E-006D)
- {
- d1 = this.n < 0.0D ? -90.0D : 90.0D;
- }
- else
- {
- double d9 = Math.Pow(6371.2290000000003D * this.F / d8, 1.0D / this.n);
- d1 = this.ToDegrees(2.0D * Math.Atan(d9) - 1.570796326794897D);
- }
- paramCoordinateLatLon.Lat = d1;
- paramCoordinateLatLon.Lon = d2;
- return paramCoordinateLatLon;
- }
- }
- public struct CoordinateXY
- {
- public double X;
- public double Y;
- }
- public struct CoordinateLatLon
- {
- public double Lat;
- public double Lon;
- public static double LonNormal(double paramDouble)
- {
- if ((paramDouble < -180.0D) || (paramDouble > 180.0D))
- {
- return Math.IEEERemainder(paramDouble, 360.0D);
- }
- return paramDouble;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement