private void buttonLBToXnYe_Click(object sender, EventArgs e) { double Ye, Xn; double L = 0; double.TryParse(this.textBoxL.Text.Trim(), out L); double B = 0; double.TryParse(this.textBoxB.Text.Trim(), out B); LonWide lw = (LonWide)int.Parse(this.comboBoxLonWide.SelectedValue.ToString()); int delno = int.Parse(this.textBoxDELNO.Text.Trim()); this.m_CoordHelper.GaussPrjCalculate(L, B, lw, delno, out Ye, out Xn); this.textBoxYe.Text = Ye.ToString(); this.textBoxXn.Text = Xn.ToString(); }
private void buttonXnYeToLB_Click(object sender, EventArgs e) { double Xn = 0; double.TryParse(this.textBoxXn.Text.Trim(), out Xn); double Ye = 0; double.TryParse(this.textBoxYe.Text.Trim(), out Ye); LonWide lw = (LonWide)int.Parse(this.comboBoxLonWide.SelectedValue.ToString()); int delno = int.Parse(this.textBoxDELNO.Text.Trim()); double L, B; this.m_CoordHelper.GaussPrjInvCalculate(Ye, Xn, lw, delno, out L, out B); this.textBoxB.Text = B.ToString(); this.textBoxL.Text = L.ToString(); }
/// <summary> /// 高期投影正算 /// 由经纬度(单位:Decimal Degree)正算到大地坐标(单位:Metre,含带号) /// </summary> /// <param name="L">经度</param> /// <param name="B">纬度</param> /// <param name="delno">带号</param> /// <param name="lw">分度</param> public void GaussPrjCalculate(double L, double B, LonWide lw, int delno, out double Ye, out double Xn) { double T, C, A, M, N, L0; //获取中央经线 switch (lw) { case LonWide.L6: L0 = delno * 6 - 3; break; case LonWide.L3: L0 = delno * 3; break; default: L0 = delno * 6 - 3; break; } L0 = L0 * Math.PI / 180; //弧度计算 L = L * Math.PI / 180; B = B * Math.PI / 180; T = Math.Tan(B) * Math.Tan(B); C = m_ee * m_ee * Math.Cos(B) * Math.Cos(B); A = (L - L0) * Math.Cos(B); M = m_a * ( (1 - Math.Pow(m_e, 2.0) / 4 - 3 * Math.Pow(m_e, 4.0) / 64 - 5 * Math.Pow(m_e, 6) / 256) * B - (3 * Math.Pow(m_e, 2.0) / 8 + 3 * Math.Pow(m_e, 4.0) / 32 + 45 * Math.Pow(m_e, 6.0) / 1024) * Math.Sin(2 * B) + (15 * Math.Pow(m_e, 4.0) / 256 + 45 * Math.Pow(m_e, 6.0) / 1024) * Math.Sin(4 * B) - (35 * Math.Pow(m_e, 6.0) / 3072) * Math.Sin(6 * B) ); N = m_a / Math.Sqrt(1 - m_e * m_e * Math.Sin(B) * Math.Sin(B)); Xn = k0 * ( M + N * Math.Tan(B) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * Math.Pow(A, 4.0) / 24) + (61 - 58 * T + T * T + 270 * C - 330 * T * C) * Math.Pow(A, 6.0) / 720 ); Ye = FE + k0 * N * (A + (1 - T + C) * Math.Pow(A, 3.0) / 6 + (5 - 18 * T + T * T + 14 * C - 58 * T * C) * Math.Pow(A, 5.0) / 120); }
/// <summary> /// 高斯投影反算 /// 大地坐标(单位:Metre,不含带号)反算到经纬度坐标(单位,Decimal Degree) /// </summary> /// <param name="Ye">大地坐标X值(不含带号)</param> /// <param name="Xn">大地坐标Y值</param> /// <param name="delno">带号</param> /// <param name="lw">分度</param> public void GaussPrjInvCalculate(double Ye, double Xn, LonWide lw, int delno, out double L, out double B) { double Nf, Rf, Bf, fi, Mf, Tf, Cf, D, L0, e1; //获取中央经线 switch (lw) { case LonWide.L6: L0 = delno * 6 - 3; break; case LonWide.L3: L0 = delno * 3; break; default: L0 = delno * 6 - 3; break; } e1 = (1 - m_b / m_a) / (1 + m_b / m_a); Mf = (Xn - FN) / k0; fi = Mf / (m_a * (1 - m_e * m_e / 4 - 3 * Math.Pow(m_e, 4) / 64 - 5 * Math.Pow(m_e, 6) / 256)); Bf = fi + (3 * e1 / 2 - 27 * Math.Pow(e1, 3) / 32) * Math.Sin(2 * fi) + (21 * e1 * e1 / 16 - 55 * Math.Pow(e1, 4) / 32) * Math.Sin(4 * fi) + (151 * Math.Pow(e1, 3) / 96) * Math.Sin(6 * fi); Nf = m_a / Math.Sqrt(1 - m_e * m_e * Math.Sin(Bf) * Math.Sin(Bf)); Rf = (m_a * (1 - m_e * m_e)) / Math.Sqrt(Math.Pow((1 - m_e * m_e * Math.Sin(Bf) * Math.Sin(Bf)), 3)); Tf = Math.Tan(Bf) * Math.Tan(Bf); Cf = m_ee * m_ee * Math.Cos(Bf) * Math.Cos(Bf); D = (Ye - FE) / Nf; B = Bf - (Nf * Math.Tan(Bf) / Rf) * ( D * D / 2 - (5 + 3 * Tf + Cf - 9 * Tf * Cf) * Math.Pow(D, 4) / 24 + (61 + 90 * Tf + 45 * Tf * Tf) * Math.Pow(D, 6) / 720 ); B = B * 180 / Math.PI; L = (1 / Math.Cos(Bf)) * ( D - (1 + 2 * Tf + Cf) * Math.Pow(D, 3) / 6 + (5 + 28 * Tf + 6 * Cf + 8 * Tf * Cf + 24 * Tf * Tf) * Math.Pow(D, 5) / 120 ); L = L * 180 / Math.PI + L0; }
private void buttonExportTFHCoord_Click(object sender, EventArgs e) { this.m_CurrentSpheroid = (Spheroid)int.Parse(this.comboBoxCoordinateSystem.SelectedValue.ToString()); this.m_CoordHelper = CoordinateFactory.CreateCoordinate(this.m_CurrentSpheroid); SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"; saveDialog.FilterIndex = 1; saveDialog.RestoreDirectory = true; if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = saveDialog.FileName; Stream fs = saveDialog.OpenFile(); using (StreamWriter sw = new StreamWriter(fs)) { List <string> xyList = new List <string>(); foreach (TFHObject obj in this.m_AllTFHS) { string[] xys = obj.Extent.Split(','); if (xys.Length == 4) { double ltl = double.Parse(xys[0]); double ltb = double.Parse(xys[1]); double rbl = double.Parse(xys[2]); double rbb = double.Parse(xys[3]); double ltYe, ltXn, rbYe, rbXn; LonWide lw = (LonWide)int.Parse(this.comboBoxLonWide.SelectedValue.ToString()); int delno = int.Parse(this.textBoxDELNO.Text.Trim()); this.m_CoordHelper.GaussPrjCalculate(ltl, ltb, lw, delno, out ltYe, out ltXn); this.m_CoordHelper.GaussPrjCalculate(rbl, rbb, lw, delno, out rbYe, out rbXn); string lbinfo = string.Format("{0} {1} {2} {3}", ltl, ltb, rbl, rbb); string xyinfo = string.Format("{0} {1} {2} {3}", ltYe, ltXn, rbYe, rbXn); string tfhinfo = string.Format("{0},{1},{2}", obj.TFH, lbinfo, xyinfo); sw.WriteLine(tfhinfo); } } } } }
private void buttonExportXYTFHShape_Click(object sender, EventArgs e) { if (this.m_AllTFHS.Count > 0) { this.m_CurrentSpheroid = (Spheroid)int.Parse(this.comboBoxCoordinateSystem.SelectedValue.ToString()); this.m_CoordHelper = CoordinateFactory.CreateCoordinate(this.m_CurrentSpheroid); MapScaleObject scaleObj = this.comboBoxLTRBMapScale.SelectedItem as MapScaleObject; SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "Shape文件(*.shp)|*.*|所有文件(*.*)|*.*"; saveDialog.FilterIndex = 1; saveDialog.RestoreDirectory = true; saveDialog.FileName = "XY-" + scaleObj.Scale.ToString(); if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = saveDialog.FileName; List <string> xyList = new List <string>(); //获取第一个和最后一格 TFHObject firstTFHObj = null; TFHObject endTFHObj = null; int tmpHs = 0; int tmpLs = 0; firstTFHObj = this.m_AllTFHS[0]; endTFHObj = this.m_AllTFHS[this.m_AllTFHS.Count - 1]; for (int i = 0; i < this.m_AllTFHS.Count; i++) { if (this.m_AllTFHS[i].H1 == firstTFHObj.H1) { tmpLs++; } else { break; } } tmpHs = this.m_AllTFHS.Count / tmpLs; double ltYe, ltXn, rbYe, rbXn; LonWide lw = (LonWide)int.Parse(this.comboBoxLonWide.SelectedValue.ToString()); int delno = int.Parse(this.textBoxDELNO.Text.Trim()); string[] firstTLXYs = firstTFHObj.Extent.Split(','); string[] endRBXYs = endTFHObj.Extent.Split(','); double ltl = double.Parse(firstTLXYs[0]); double ltb = double.Parse(firstTLXYs[1]); double rbl = double.Parse(endRBXYs[2]); double rbb = double.Parse(endRBXYs[3]); this.m_CoordHelper.GaussPrjCalculate(ltl, ltb, lw, delno, out ltYe, out ltXn); this.m_CoordHelper.GaussPrjCalculate(rbl, rbb, lw, delno, out rbYe, out rbXn); double rXn = 0, rYe = 0; rXn = Math.Abs((ltXn - rbXn) / tmpHs); rYe = Math.Abs((rbYe - ltYe) / tmpLs); for (int i = 0; i < this.m_AllTFHS.Count; i++) { double tmpLTYe = 0, tmpLTXn = 0, tmpRBYe = 0, tmpRBXn = 0; int tmpH = (int)(Math.Floor((double)(i / tmpLs))); int tmpL = (int)(i % tmpLs); string xy = string.Empty; tmpLTYe = ltYe + rYe * tmpL; tmpLTXn = ltXn - rXn * tmpH; tmpRBYe = ltYe + rYe * (tmpL + 1); tmpRBXn = ltXn - rXn * (tmpH + 1); xy += string.Format("{0},", this.m_AllTFHS[i].TFH); xy += string.Format("{0} {1},", tmpLTYe, tmpRBXn); xy += string.Format("{0} {1},", tmpLTYe, tmpLTXn); xy += string.Format("{0} {1},", tmpRBYe, tmpLTXn); xy += string.Format("{0} {1},", tmpRBYe, tmpRBXn); xy += string.Format("{0} {1}", tmpLTYe, tmpRBXn); xyList.Add(xy); } try { ShapeUtility.ExportShapeFile(fileName, xyList); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }