static void Main(string[] args) { try { TransverseMercatorExact proj = new TransverseMercatorExact(); // 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)); } }
private void SetTransverseExact() { 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_transExact = new TransverseMercatorExact(a, f, k, false); break; default: break; } m_centralScaleTextBox.Text = m_transExact.CentralScale.ToString(); }
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); }
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); } }