private static EsriPrjFile AsEsriPrjFile(TransverseMercator transverseMercator) { EsriPrjTreeNode root = new EsriPrjTreeNode(); root.Name = EsriPrjFile._projcs; root.Values = new List <string>() { string.IsNullOrWhiteSpace(transverseMercator.Title) ? "Transverse Mercator" : transverseMercator.Title }; var geogcs = new EsriPrjTreeNode(transverseMercator.Ellipsoid, transverseMercator.DatumName, transverseMercator.Ellipsoid.Srid); var projection = new EsriPrjTreeNode(EsriPrjFile._projection, EsriPrjFile._esriTransverseMercator); var falseEasting = new EsriPrjTreeNode(EsriPrjFile._parameter, EsriPrjFile._falseEasting, transverseMercator.FalseEasting.AsExactString()); var falseNorthing = new EsriPrjTreeNode(EsriPrjFile._parameter, EsriPrjFile._falseNorthing, transverseMercator.FalseNorthing.AsExactString()); var centralMeridian = new EsriPrjTreeNode(EsriPrjFile._parameter, EsriPrjFile._centralMeridian, transverseMercator.CentralMeridian.AsExactString()); var scaleFactor = new EsriPrjTreeNode(EsriPrjFile._parameter, EsriPrjFile._scaleFactor, transverseMercator.ScaleFactor.AsExactString()); var latitudeOfOrigin = new EsriPrjTreeNode(EsriPrjFile._parameter, EsriPrjFile._latitudeOfOrigin, transverseMercator.StandardParallel2.AsExactString()); var unit = EsriPrjTreeNode.MeterUnit; root.Children = new List <EsriPrjTreeNode>() { geogcs, projection, falseEasting, falseNorthing, centralMeridian, scaleFactor, latitudeOfOrigin, unit }; return(new EsriPrjFile(root)); }
public Form1() { InitializeComponent(); // load Oracle this.oracleConnection1.ConnectionString = "user id=" + "coreview" + ";password="******"coreview" + ";data source=" + "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)" + "(HOST=" + "gdratl.ess.nrcan.gc.ca" + ")(PORT=" + "1521" + "))(CONNECT_DATA=" + "(SERVICE_NAME=" + "gdratl.ess.nrcan.gc.ca" + ")))"; // load ED expeds this.oracleConnection1.Open(); this.oracleCommand1.Connection = this.oracleConnection1; DataSet ds = new DataSet(); this.oracleCommand1.CommandText = "SELECT EXPED_CD, EXPED_YEAR FROM CORE.EXPEDITION WHERE (EXPED_CD IN (SELECT DISTINCT EXPED_CD FROM CORE.SEISMIC_PARAMETER)) ORDER BY EXPED_YEAR, EXPED_CD"; this.oracleDataAdapter1.SelectCommand = this.oracleCommand1; this.oracleDataAdapter1.Fill(ds, "Cruise List"); NETGeographicLib.TransverseMercator tm = new TransverseMercator(); }
/// <summary> /// 构建不同的投影变换方法 /// </summary> /// <param name="projection"></param> /// <param name="ellipsoid"></param> /// <param name="unit"></param> /// <returns></returns> private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); //长轴 parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); //短轴 parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); //单位弧度 IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "gauss_kruger": //高斯克吕格投影 transform = new GaussKrugerProjection(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "krovak": transform = new KrovakProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return(transform); }
public void OsgbTest() { var projection = new TransverseMercator( new GeographicCoordinate(49 * Math.PI / 180, -2 * Math.PI / 180), new Vector2(400000, -100000), 0.9996012717, new SpheroidEquatorialInvF(6377563.396, 299.32496) ); var a = new Point2(651409.903, 313177.270); var b = new GeographicCoordinate(52.6576 * Math.PI / 180, 1.7179 * Math.PI / 180); var projected = projection.TransformValue(b); Assert.AreEqual(a.X, projected.X, 2); Assert.AreEqual(a.Y, projected.Y, 4); }
public void OsgbInverseTest() { var projection = new TransverseMercator( new GeographicCoordinate(49 * Math.PI / 180, -2 * Math.PI / 180), new Vector2(400000, -100000), 0.9996012717, new SpheroidEquatorialInvF(6377563.396, 299.32496) ); var a = new Point2(651409.903, 313177.270); var b = new GeographicCoordinate(52.6576 * Math.PI / 180, 1.7179 * Math.PI / 180); var unProjected = projection.GetInverse().TransformValue(a); Assert.AreEqual(b.Latitude, unProjected.Latitude, 0.0000006); Assert.AreEqual(b.Longitude, unProjected.Longitude, 0.0000004); }
private void SetTransverse() { switch (m_constructorComboBox.SelectedIndex) { case 1: double a = Double.Parse(m_majorRadiusTextBox.Text); double f = Double.Parse(m_flatteningTextBox.Text); double k = Double.Parse(m_KTextBox.Text); m_trans = new TransverseMercator(a, f, k); break; default: break; } m_centralScaleTextBox.Text = m_trans.CentralScale.ToString(); }
public void EpsgExample1351Test() { var projection = new TransverseMercator( new GeographicCoordinate(0.85521133, -0.03490659), new Vector2(400000.00, -100000.00), 0.9996012717, new SpheroidEquatorialInvF(6377563.396, 299.32496) ); var input = new GeographicCoordinate(0.88139127, 0.00872665); var expected = new Point2(577274.99, 69740.50); var result = projection.TransformValue(input); Assert.AreEqual(expected.X, result.X, 0.03); Assert.AreEqual(expected.Y, result.Y, 0.002); }
/// <summary> /// Constructor for a ellipsoid with equatorial radius and flattening. /// </summary> /// <param name="a">Equatorial radius (meters).</param> /// <param name="f">Flattening of ellipsoid. Setting <i>f</i> = 0 gives a sphere.</param> public Ellipsoid(double a, double f) { stol_ = 0.01 * Sqrt(DBL_EPSILON); _a = a; _f = f; _f1 = 1 - _f; _f12 = Sq(_f1); _e2 = _f * (2 - _f); _es = (_f < 0 ? -1 : 1) * Sqrt(Abs(_e2)); _e12 = _e2 / (1 - _e2); _n = _f / (2 - _f); _b = _a * _f1; _tm = new TransverseMercator(_a, _f, 1d); _ell = new EllipticFunction(-_e12); _au = new AlbersEqualArea(_a, _f, 0d, 1d, 0d, 1d, 1d); }
public void EpsgExample1351InverseTest() { var projection = new TransverseMercator( new GeographicCoordinate(0.85521133, -0.03490659), new Vector2(400000.00, -100000.00), 0.9996012717, new SpheroidEquatorialInvF(6377563.396, 299.32496) ); var input = new Point2(577274.99, 69740.50); var expected = new GeographicCoordinate(0.88139127, 0.00872665); var result = projection.GetInverse().TransformValue(input); Assert.AreEqual(expected.Latitude, result.Latitude, 0.00000000004); Assert.AreEqual(expected.Longitude, result.Longitude, 0.000000008); }
public void TransverseMercatorProj6() { var tme = new TransverseMercatorExact(6.4e6, 1d / 150, Constants.UTM_k0); var(lat, lon) = tme.Reverse(0, 3.3e6, 2.5e6, out var gamma, out var k); Assert.AreEqual(19.80370996793, lat, 1e-11); Assert.AreEqual(30.24919702282, lon, 1e-11); Assert.AreEqual(11.214378172893, gamma, 1e-12); Assert.AreEqual(1.137025775759, k, 1e-12); var tm = new TransverseMercator(6.4e6, 1d / 150, Constants.UTM_k0); (lat, lon) = tm.Reverse(0, 3.3e6, 2.5e6, out gamma, out k); Assert.AreEqual(19.80370996793, lat, 1e-11); Assert.AreEqual(30.24919702282, lon, 1e-11); Assert.AreEqual(11.214378172893, gamma, 1e-12); Assert.AreEqual(1.137025775759, k, 1e-12); }
public void TransverseMercatorProj4_CheckUseOfComplexArithmeticToDoClenshawSum() { var tme = new TransverseMercatorExact(6.4e6, 1d / 150, Constants.UTM_k0); var(x, y) = tme.Forward(0, 20, 30, out var gamma, out var k); Assert.AreEqual(3266035.453860, x, 1e-6); Assert.AreEqual(2518371.552676, y, 1e-6); Assert.AreEqual(11.207356502141, gamma, 1e-12); Assert.AreEqual(1.134138960741, k, 1e-12); var tm = new TransverseMercator(6.4e6, 1d / 150, Constants.UTM_k0); (x, y) = tm.Forward(0, 20, 30, out gamma, out k); Assert.AreEqual(3266035.453860, x, 1e-6); Assert.AreEqual(2518371.552676, y, 1e-6); Assert.AreEqual(11.207356502141, gamma, 1e-12); Assert.AreEqual(1.134138960741, k, 1e-12); }
public void TransverseMercatorProj2_TestFixToBadScaleAtPoleWithTransverseMercatorExact() { var tme = new TransverseMercatorExact(Ellipsoid.WGS84, 1); var(lat, lon) = tme.Reverse(0, 0, 10001965.7293127228, out var gamma, out var k); Assert.AreEqual(90.0, lat, 0.01); Assert.AreEqual(0, lon, 0.01); Assert.AreEqual(0, gamma, 0.01); Assert.AreEqual(1, k, 1e-5); var tm = new TransverseMercator(Ellipsoid.WGS84, 1); (lat, lon) = tm.Reverse(0, 0, 10001965.7293127228, out gamma, out k); Assert.AreEqual(90.0, lat, 0.01); Assert.AreEqual(180, Math.Abs(lon), 0.01); Assert.AreEqual(180, Math.Abs(gamma), 0.01); Assert.AreEqual(1, k, 1e-5); }
public void TransverseMercatorProj0_TestFixToBadMeridianConvergence() { var tme = new TransverseMercatorExact(Ellipsoid.WGS84, 1); var(x, y) = tme.Forward(0, 90, 75, out var gamma, out var k); Assert.AreEqual(0.0, x, 0.01); Assert.AreEqual(10001965.7293, y, 0.0001); Assert.AreEqual(75.0, gamma, 0.01); Assert.AreEqual(1.0, k, 0.01); var tm = new TransverseMercator(Ellipsoid.WGS84, 1); (x, y) = tm.Forward(0, 90, 75, out gamma, out k); Assert.AreEqual(0.0, x, 0.01); Assert.AreEqual(10001965.7293, y, 0.0001); Assert.AreEqual(75.0, gamma, 0.01); Assert.AreEqual(1.0, k, 0.01); }
public point(long t, double x, double y, bool polar, double _referenceMeridian) { ti = t; xi = x; yi = y; zonei = zone; active = true; referenceMeridian = _referenceMeridian; if (x > -360.0 && x <= 360.0 && y >= -90.0 && y <= 90.0) { NETGeographicLib.TransverseMercator p = new TransverseMercator(a, f, k1); p.Forward(referenceMeridian, y, x, out xx, out yy); } else { xx = x; yy = y; } }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid) { List <ProjectionParameter> parameterList = new List <ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) { parameterList.Add(projection.GetParameter(i)); } parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); IMathTransform transform = null; switch (projection.ClassName.ToLower()) { case "mercator_1sp": case "mercator_2sp": //1SP transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": transform = new AlbersProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return(transform); }
// create an interpolated point between point a and b at time t public point interpolatedPoint(point p1, point p2, long t) { double ts = point.codedTimeIntoSeconds(t); double xx = p1.xm() + (ts - p1.tsec()) * (p2.xm() - p1.xm()) / (p2.tsec() - p1.tsec()); double yy = p1.ym() + (ts - p1.tsec()) * (p2.ym() - p1.ym()) / (p2.tsec() - p1.tsec()); double x, y; if (p1.x > -360.0 && p1.x <= 360.0 && p1.y >= -90.0 && p1.y <= 90.0) { NETGeographicLib.TransverseMercator p = new TransverseMercator(a, f, k1); p.Reverse(referenceMeridian, xx, yy, out y, out x); } else { x = xx; y = yy; } point newpont = new point(t, x, y, true, referenceMeridian); return(newpont); }
public void Test(string geoResourceName, string prjResourceName, double projectDelta, double unprojectDelta) { var latLonData = GoldData.GetReadyReader(geoResourceName); var prjData = GoldData.GetReadyReader(prjResourceName); var spheroid = GoldData.GenerateSpheroid(prjData["DATUM"]); var projection = new TransverseMercator( new GeographicCoordinate( Double.Parse(prjData["ORIGIN LATITUDE"]) * Math.PI / 180.0, Double.Parse(prjData["CENTRAL MERIDIAN"]) * Math.PI / 180.0 ), new Vector2( Double.Parse(prjData["FALSE EASTING"]), Double.Parse(prjData["FALSE NORTHING"]) ), Double.Parse(prjData["SCALE FACTOR"]), spheroid ); var inverse = projection.GetInverse(); while (latLonData.Read() && prjData.Read()) { var coord = latLonData.CurrentLatLon(); var coordRads = latLonData.CurrentLatLonRadians(); var expected = prjData.CurrentPoint2D(); var projected = projection.TransformValue(coordRads); Assert.AreEqual(expected.X, projected.X, projectDelta); Assert.AreEqual(expected.Y, projected.Y, projectDelta); var unProjected = inverse.TransformValue(expected); unProjected = new GeographicCoordinate(unProjected.Latitude * 180.0 / Math.PI, unProjected.Longitude * 180.0 / Math.PI); Assert.AreEqual(coord.Latitude, unProjected.Latitude, unprojectDelta); Assert.AreEqual(coord.Longitude, unProjected.Longitude, unprojectDelta); } }
static void Main(string[] args) { try { TransverseMercator proj = new TransverseMercator(); // WGS84 double lon0 = -75; // Central meridian for UTM zone 18 { // Sample forward calculation double lat = 40.3, lon = -74.7; // Princeton, NJ double x, y; proj.Forward(lon0, lat, lon, out x, out y); Console.WriteLine(String.Format("{0} {1}", x, y)); } { // Sample reverse calculation double x = 25e3, y = 4461e3; double lat, lon; proj.Reverse(lon0, x, y, out lat, out lon); Console.WriteLine(String.Format("{0} {1}", lat, lon)); } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught exception: {0}", e.Message)); } }
public UTM(int zone, Hemisphere hemisphere) { Projection = new TransverseMercator(zone * 6.0 - 183, 0, 0.9996, Spheroid.WGS84); FalseNorthing = hemisphere == Hemisphere.North ? 0 : 10000000; FalseEasting = 500000; }
private void OnConstructorChanged(object sender, EventArgs e) { try { if (m_projectionComboBox.SelectedIndex > 1) { m_originLatitudeTextBox.ReadOnly = true; m_originLatitudeTextBox.Text = "N/A"; if (m_constructorComboBox.SelectedIndex == 0) { m_convertButton.Enabled = true; m_setButton.Enabled = false; m_majorRadiusTextBox.ReadOnly = true; m_flatteningTextBox.ReadOnly = true; m_scaleLabel.Hide(); m_KTextBox.Hide(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); if (m_projection == ProjectionTypes.TransverseMercator) { m_trans = new TransverseMercator(); m_centralScaleTextBox.Text = m_trans.CentralScale.ToString(); } else { m_transExact = new TransverseMercatorExact(); m_centralScaleTextBox.Text = m_transExact.CentralScale.ToString(); } } else { m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); } } else { m_originLatitudeTextBox.ReadOnly = false; switch (m_constructorComboBox.SelectedIndex) { case 0: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Standard Latitude (degrees)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; case 1: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Standard Latitude 1 (degrees)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Text = "Standard Latitude 2 (degrees)"; m_stdLat2Label.Show(); m_stdLat2TextBox.Show(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; case 2: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Sin(Lat1)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Text = "Cos(Lat1)"; m_stdLat2Label.Show(); m_stdLat2TextBox.Show(); m_sinLat2Label.Show(); m_sinLat2TextBox.Show(); m_cosLat2Label.Show(); m_cosLat2TextBox.Show(); break; default: m_convertButton.Enabled = true; m_setButton.Enabled = false; m_majorRadiusTextBox.ReadOnly = true; m_flatteningTextBox.ReadOnly = true; m_scaleLabel.Hide(); m_KTextBox.Hide(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; } if (m_projection == ProjectionTypes.AlbersEqualArea) AlbersConstructorChanged(); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static IMathTransform CreateCoordinateOperation(IProjection projection, IEllipsoid ellipsoid, ILinearUnit unit) { List<ProjectionParameter> parameterList = new List<ProjectionParameter>(projection.NumParameters); for (int i = 0; i < projection.NumParameters; i++) parameterList.Add(projection.GetParameter(i)); parameterList.Add(new ProjectionParameter("semi_major", ellipsoid.SemiMajorAxis)); parameterList.Add(new ProjectionParameter("semi_minor", ellipsoid.SemiMinorAxis)); parameterList.Add(new ProjectionParameter("unit", unit.MetersPerUnit)); IMathTransform transform = null; switch (projection.ClassName.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_')) { case "mercator": case "mercator_1sp": case "mercator_2sp": transform = new Mercator(parameterList); break; case "transverse_mercator": transform = new TransverseMercator(parameterList); break; case "albers": case "albers_conic_equal_area": transform = new AlbersProjection(parameterList); break; case "lambert_conformal_conic": case "lambert_conformal_conic_2sp": case "lambert_conic_conformal_(2sp)": transform = new LambertConformalConic2SP(parameterList); break; default: throw new NotSupportedException(String.Format("Projection {0} is not supported.", projection.ClassName)); } return transform; }
private void OnValidate(object sender, EventArgs e) { try { const double DEG_TO_RAD = 3.1415926535897932384626433832795 / 180.0; AlbersEqualArea a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); double radius = a.EquatorialRadius; double f = a.Flattening; a = new AlbersEqualArea(radius, f, 60.0, 1.0); a = new AlbersEqualArea(radius, f, 60.0, 70.0, 1.0); a = new AlbersEqualArea(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); double lon0 = 0.0, lat = 32.0, lon = -86.0, x, y, gamma, k, x1, y1; a.Forward(lon0, lat, lon, out x, out y, out gamma, out k); a.Forward(lon0, lat, lon, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in AlbersEqualArea.Forward"); } a.Reverse(lon0, x, y, out lat, out lon, out gamma, out k); a.Reverse(lon0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in AlbersEqualArea.Reverse"); } LambertConformalConic b = new LambertConformalConic(radius, f, 60.0, 1.0); b = new LambertConformalConic(radius, f, 60.0, 65.0, 1.0); b = new LambertConformalConic(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); b = new LambertConformalConic(); b.SetScale(60.0, 1.0); b.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); b.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in LambertConformalConic.Forward"); } b.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); b.Reverse(-87.0, x, y, out x1, out y1, out gamma, out k); if (lat != x1 || lon != y1) { throw new Exception("Error in LambertConformalConic.Reverse"); } TransverseMercator c = new TransverseMercator(radius, f, 1.0); c = new TransverseMercator(); c.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); c.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in TransverseMercator.Forward"); } c.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); c.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in TransverseMercator.Reverse"); } TransverseMercatorExact d = new TransverseMercatorExact(radius, f, 1.0, false); d = new TransverseMercatorExact(); d.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); d.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in TransverseMercatorExact.Forward"); } d.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); d.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in TransverseMercatorExact.Reverse"); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void OnConstructorChanged(object sender, EventArgs e) { try { if (m_projectionComboBox.SelectedIndex > 1) { m_originLatitudeTextBox.ReadOnly = true; m_originLatitudeTextBox.Text = "N/A"; if (m_constructorComboBox.SelectedIndex == 0) { m_convertButton.Enabled = true; m_setButton.Enabled = false; m_majorRadiusTextBox.ReadOnly = true; m_flatteningTextBox.ReadOnly = true; m_scaleLabel.Hide(); m_KTextBox.Hide(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); if (m_projection == ProjectionTypes.TransverseMercator) { m_trans = new TransverseMercator(); m_centralScaleTextBox.Text = m_trans.CentralScale.ToString(); } else { m_transExact = new TransverseMercatorExact(); m_centralScaleTextBox.Text = m_transExact.CentralScale.ToString(); } } else { m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); } } else { m_originLatitudeTextBox.ReadOnly = false; switch (m_constructorComboBox.SelectedIndex) { case 0: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Standard Latitude (degrees)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; case 1: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Standard Latitude 1 (degrees)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Text = "Standard Latitude 2 (degrees)"; m_stdLat2Label.Show(); m_stdLat2TextBox.Show(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; case 2: m_convertButton.Enabled = false; m_setButton.Enabled = true; m_majorRadiusTextBox.ReadOnly = false; m_flatteningTextBox.ReadOnly = false; m_scaleLabel.Show(); m_KTextBox.Show(); m_stdLatLabel.Show(); m_stdLatLabel.Text = "Sin(Lat1)"; m_stdLat1TextBox.Show(); m_stdLat2Label.Text = "Cos(Lat1)"; m_stdLat2Label.Show(); m_stdLat2TextBox.Show(); m_sinLat2Label.Show(); m_sinLat2TextBox.Show(); m_cosLat2Label.Show(); m_cosLat2TextBox.Show(); break; default: m_convertButton.Enabled = true; m_setButton.Enabled = false; m_majorRadiusTextBox.ReadOnly = true; m_flatteningTextBox.ReadOnly = true; m_scaleLabel.Hide(); m_KTextBox.Hide(); m_stdLatLabel.Hide(); m_stdLat1TextBox.Hide(); m_stdLat2Label.Hide(); m_stdLat2TextBox.Hide(); m_sinLat2Label.Hide(); m_sinLat2TextBox.Hide(); m_cosLat2Label.Hide(); m_cosLat2TextBox.Hide(); break; } if (m_projection == ProjectionTypes.AlbersEqualArea) { AlbersConstructorChanged(); } } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnValidate(object sender, EventArgs e) { try { const double DEG_TO_RAD = 3.1415926535897932384626433832795 / 180.0; AlbersEqualArea a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); double radius = a.MajorRadius; double f = a.Flattening; a = new AlbersEqualArea(radius, f, 60.0, 1.0); a = new AlbersEqualArea(radius, f, 60.0, 70.0, 1.0); a = new AlbersEqualArea(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0*DEG_TO_RAD), Math.Cos(89.0*DEG_TO_RAD), 1.0); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); double lon0 = 0.0, lat = 32.0, lon = -86.0, x, y, gamma, k, x1, y1; a.Forward(lon0, lat, lon, out x, out y, out gamma, out k); a.Forward(lon0, lat, lon, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in AlbersEqualArea.Forward"); a.Reverse(lon0, x, y, out lat, out lon, out gamma, out k); a.Reverse(lon0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in AlbersEqualArea.Reverse"); LambertConformalConic b = new LambertConformalConic(radius, f, 60.0, 1.0); b = new LambertConformalConic(radius, f, 60.0, 65.0, 1.0); b = new LambertConformalConic(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); b = new LambertConformalConic(); b.SetScale(60.0, 1.0); b.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); b.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in LambertConformalConic.Forward"); b.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); b.Reverse(-87.0, x, y, out x1, out y1, out gamma, out k); if (lat != x1 || lon != y1) throw new Exception("Error in LambertConformalConic.Reverse"); TransverseMercator c = new TransverseMercator(radius, f, 1.0); c = new TransverseMercator(); c.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); c.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in TransverseMercator.Forward"); c.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); c.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in TransverseMercator.Reverse"); TransverseMercatorExact d = new TransverseMercatorExact(radius, f, 1.0, false); d = new TransverseMercatorExact(); d.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); d.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in TransverseMercatorExact.Forward"); d.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); d.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in TransverseMercatorExact.Reverse"); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }