基本信息
源码名称:C# 高斯正反算,邻带换算代码
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2019-04-04
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
一个用C#写的高斯坐标正反算,包括邻带换算、不分带计算。控制测量高斯正反算以及邻带换算程序代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace Gauss
    
{
    public partial class Form1 : Form
    {
        private BackgroundWorker bkWorker = new BackgroundWorker();
        private int percentValue = 0;
        public Form1()
        {
            InitializeComponent();
            bkWorker.WorkerReportsProgress = true;
            bkWorker.WorkerSupportsCancellation = true;
            bkWorker.DoWork  = new DoWorkEventHandler(DoWork);
            bkWorker.ProgressChanged  = new ProgressChangedEventHandler(ProgessChanged);
            bkWorker.RunWorkerCompleted  = new RunWorkerCompletedEventHandler(CompleteWork);  

        }
       /* private void btnStart_Click(object sender, EventArgs e)
        {
            percentValue = 10;
            this.progressBar1.Maximum = 1000;
            // 执行后台操作  
            bkWorker.RunWorkerAsync();
        }*/

        public void DoWork(object sender, DoWorkEventArgs e)
        {
            // 事件处理,指定处理函数  
            e.Result = ProcessProgress(bkWorker, e);
        }

        public void ProgessChanged(object sender, ProgressChangedEventArgs e)
        {
            // bkWorker.ReportProgress 会调用到这里,此处可以进行自定义报告方式  
            this.progressBar1.Value = e.ProgressPercentage;
            int percent = (int)(e.ProgressPercentage / percentValue);
            this.label1.Text = "处理进度:"   Convert.ToString(percent)   "%";
        }

        public void CompleteWork(object sender, RunWorkerCompletedEventArgs e)
        {
            this.label1.Text = "处理完毕!";
        }

        private int ProcessProgress(object sender, DoWorkEventArgs e)
        {
            string[,] _miuia1;//保存坐标转换结果的二维数组
            for (int i = 0; i <= 1000; i  )
            {

                Extract_Coordinates.Save(file, out _miuia1, out Count);
                if (bkWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return -1;
                }
                else
                {
                    // 状态报告  
                    bkWorker.ReportProgress(i);

                    // 等待,用于UI刷新界面,很重要  
                    System.Threading.Thread.Sleep(1);
                }
            }

            return -1;
        }  

        double B, L;
        double X, Y;
        int Count;//点的个数
        string NoBeltNumData;//Y不带带号的坐标
        string WithBeltNumData;//Y带带号的坐标
        string file;
        File Extract_Coordinates = new File();//字符串分割类对象以提取坐标
        Angle angle = new Angle();//角度转换类对象
       
        //导入数据按钮事件以选择导入的文件
        private void 导入数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = " 选择文件";
            openFileDialog1.FileName = "";
            openFileDialog1.Filter = "txt文件|*.txt";
            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
            {
                StreamReader readfile = new StreamReader(openFileDialog1.FileName, true);
                file = readfile.ReadToEnd();
                readfile.Close();
            }
            else
            {
                openFileDialog1.Dispose();
                this.Show();
            }
            
        }

        private void 开始转换_Click(object sender, EventArgs e)//单击分带计算选项卡中的转换按钮
        {
          //  this.backgroundWorker1.RunWorkerAsync();//运行backgroundWorker1组件
            try
            {
                string[,] _miuia1;//保存坐标转换结果的二维数组
                Extract_Coordinates.Save(file, out _miuia1, out Count);
                //如果选择“高斯正算”按钮
                if (radioButton1.Checked)
                {
                    WithBeltNumData = "点号"   "\t\t\t"   "Y"   "\t\t\t"   "X"   "\r\n";
                    NoBeltNumData = "点号"   "\t\t\t"   "Y"   "\t\t\t"   "X"   "\r\n";
                    GaussCalculate JAY = new GaussCalculate(Ellipsoid.Text);//调用GaussCalculate类中的重载构造函数
                    for (int i = 0; i < Count; i  )
                    {
                        B = angle.dmsTOdeg(double.Parse(_miuia1[i, 2]));
                        L = angle.dmsTOdeg(double.Parse(_miuia1[i, 1]));
                        JAY.Calculate(B, L, out X, out Y, double.Parse(Bandwidth.Text), double.Parse(Zero_lon.Text));//调用正算重载
                        WithBeltNumData  = _miuia1[i, 0]   "\t\t"   Y.ToString("F5")   "\t\t"   X.ToString("F5")   "\r\n";//输出有带号的坐标
                        NoBeltNumData  = _miuia1[i, 0]   "\t\t"   (Y - Math.Floor(Y / 1000000) * 1000000).ToString("F5")   "\t\t"   X.ToString("F5")   "\r\n";//输出无带号的坐标
                    }
                    textBox1.Text = WithBeltNumData;//文本框中显示
                }
                //如果选择“高斯反算”按钮
                else
                {
                    GaussCalculate JAY = new GaussCalculate(Ellipsoid.Text);
                    WithBeltNumData = "点号"   "\t\t\t"   "B"   "\t\t\t\t"   "L"   "\r\n";
                    for (int i = 0; i < Count; i  )
                    {
                        JAY.Calculate(out B, out L, double.Parse(_miuia1[i, 2]), double.Parse(_miuia1[i, 1]), double.Parse(Bandwidth.Text), double.Parse(Zero_lon.Text));
                        B = angle.radTOdms(B);
                        L = angle.degTOdms(L);
                        WithBeltNumData  = _miuia1[i, 0]   "\t\t"   B.ToString()   "\t\t"   L.ToString()   "\r\n";

                    }
                    textBox1.Text = WithBeltNumData;
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }

        private void 开始转换2_Click(object sender, EventArgs e)//单击不分带计算选项卡中的转换按钮
        {
            try
            {
                string[,] _miuia1;//保存坐标转换结果的二维数组
                Extract_Coordinates.Save(file, out _miuia1, out Count);
                //如果选择“高斯正算”按钮
                if (radioButton1.Checked)
                {
                    WithBeltNumData = "点号"   "\t\t\t"   "Y"   "\t\t\t"   "X"   "\r\n";
                    GaussCalculate JAY = new GaussCalculate(Ellipsoid1.Text);
                    for (int i = 0; i < Count; i  )
                    {
                        B = angle.dmsTOdeg(double.Parse(_miuia1[i, 2]));
                        L = angle.dmsTOdeg(double.Parse(_miuia1[i, 1]));
                        JAY.Calculate(B, L, out X, out Y, double.Parse(CenterLongitude.Text));
                        WithBeltNumData  = _miuia1[i, 0]   "\t\t"   Y.ToString("F5")   "\t\t"   X.ToString("F5")   "\r\n";//输出坐标
                    }
                    textBox1.Text = WithBeltNumData;//文本框中显示计算结果

                }
                //如果选择“高斯反算”按钮
                else
                {
                    GaussCalculate JAY = new GaussCalculate(Ellipsoid1.Text);
                    WithBeltNumData = "点号"   "\t\t\t"   "B"   "\t\t\t\t"   "L"   "\r\n";
                    for (int i = 0; i < Count; i  )
                    {
                        JAY.Calculate(out B, out L, double.Parse(_miuia1[i, 2]), double.Parse(_miuia1[i, 1]), double.Parse(CenterLongitude.Text));
                        B = angle.radTOdms(B);
                        double CenterLongitude0 = angle.dmsTOdeg(double.Parse(CenterLongitude.Text));//中央子午线
                        L = angle.degTOdms(L   CenterLongitude0);//反算得到的经度差加上中央子午线
                        WithBeltNumData  = _miuia1[i, 0]   "\t\t"   B.ToString()   "\t\t"   L.ToString()   "\r\n";

                    }
                    textBox1.Text = WithBeltNumData;//文本框中显示计算结果
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }

        private void 开始转换3_Click(object sender, EventArgs e)//单击邻带换算选项卡中的转换按钮
        {
            
            try
            {
                string[,] _miuia1;//保存坐标转换结果的二维数组
                WithBeltNumData = "点号"   "\t\t\t"   "Y"   "\t\t\t"   "X"   "\r\n";
                Extract_Coordinates.Save(file, out _miuia1, out Count);
                GaussCalculate JAY = new GaussCalculate(Ellipsoid3.Text);
                for (int i = 0; i < Count; i  )
                {
                    JAY.Calculate(out B, out L, double.Parse(_miuia1[i, 2]), double.Parse(_miuia1[i, 1]), double.Parse(Bandwidth3.Text), double.Parse(Zero_lon3.Text));
                    B = angle.radTOdeg(B);
                    bool LeftOrRight;
                    if (radioButton3.Checked)//如果选择的是“左邻带”
                    {
                         LeftOrRight = true;
                    }
                    else//如果选择的是“右邻带”
                    {
                          LeftOrRight = false;
                    }
                    JAY.Calculate(B, L, out X, out Y, double.Parse(Bandwidth3.Text), double.Parse(Zero_lon3.Text), LeftOrRight);
                    WithBeltNumData  = _miuia1[i, 0]   "\t\t"   Y.ToString("F5")  "\t\t"   X.ToString("F5")   "\r\n";//输出有带号的坐标

                }
                textBox1.Text = WithBeltNumData;

            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }

        }

        private void AdjacentBelt_Enter(object sender, EventArgs e)//选择“邻带换算”选项卡时radioButton1,2为不能选择状态
        {
            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
        }

        private void AdjacentBelt_Leave(object sender, EventArgs e)//离开“邻带换算”选项卡时radioButton1,2恢复选择状态
        {
            radioButton1.Enabled = true;
            radioButton2.Enabled = true;
        }

        //高斯正算结果输出(Y坐标有带号)
        private void 有带号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                saveFileDialog1.ShowDialog();
                saveFileDialog1.Filter = "txt文件|*.txt";
                StreamWriter writefile = new StreamWriter(saveFileDialog1.FileName, true);
                writefile.WriteLine(WithBeltNumData);
                writefile.Close();
                MessageBox.Show("保存成功!");
            }
            catch
            {

                MessageBox.Show(new Exception("操作失败!").Message);
            }

        }
        //高斯正算结果输出(Y坐标不带带号)
        private void 无带号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
            saveFileDialog1.ShowDialog();
            saveFileDialog1.Filter = "txt文件|*.txt";
            StreamWriter writefile = new StreamWriter(saveFileDialog1.FileName, true);
            writefile.WriteLine(NoBeltNumData);
            writefile.Close();
            MessageBox.Show("保存成功!");
            }
            catch
            {

                MessageBox.Show(new Exception("操作失败!").Message);
            }
        }
      
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (radioButton2.Checked ||tabControl1.SelectedIndex!=0)
            {
                无带号ToolStripMenuItem.Visible = false;
                有带号ToolStripMenuItem.Visible = false;
                saveFileDialog1.Filter = "txt文件|*.txt";
                if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
                {
                    StreamWriter writefile = new StreamWriter(saveFileDialog1.FileName, true);
                    writefile.WriteLine(WithBeltNumData);
                    writefile.Close();
                    MessageBox.Show("保存成功!");
                }
                else
                {
                    saveFileDialog1.Dispose();
                    this.Show();
                }
               
            }
            

        }

        //清空文本框
        private void 重置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
            NoBeltNumData = "";
            WithBeltNumData = "";
            textBox1.ResetText();
            radioButton1.Checked = true;*/
            percentValue = 10;
            this.progressBar1.Maximum = 1000;
            // 执行后台操作  
            bkWorker.RunWorkerAsync();
           
        }
        
        //限制起始子午线输入的数据规范
        private void Zero_lon_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
                e.Handled = true;
            //小数点的处理。
            if ((int)e.KeyChar == 46)     //小数点
            {
                if (Zero_lon.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(Zero_lon.Text, out oldf);
                    b2 = float.TryParse(Zero_lon.Text   e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }

        }
        //标准3,6度带
        private void Bandwidth_SelectedValueChanged(object sender, EventArgs e)
        {
            if (Bandwidth.Text == "3")
            {
                Zero_lon.Text = "1.5";

            }
            else if (Bandwidth.Text == "6")
            {
                Zero_lon.Text = "0";


            }

        }

        //退出程序
        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

     /*   private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker work = sender as BackgroundWorker;
            for (int i = 0; i < 100; i  )
            {
                Thread.Sleep(100);
                work.ReportProgress(i);
            }
        }*/

    }
}