在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 高斯正反算,邻带换算代码

C# 高斯正反算,邻带换算代码

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.07M
  • 下载次数:38
  • 浏览次数:787
  • 发布时间:2019-04-04
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 高斯 代码

实例介绍

【实例简介】一个用C#写的高斯坐标正反算,包括邻带换算、不分带计算。控制测量高斯正反算以及邻带换算程序代码。

【实例截图】

from clipboard

【核心代码】

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);
            }
        }*/

    }
}

标签: 高斯 代码

实例下载地址

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警