格网体积计算

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 using System.IO;
 11 using System.Diagnostics;
 12 
 13 namespace My_Grid
 14 {
 15     public partial class Form1 : Form
 16     {
 17         public Form1()
 18         {
 19             InitializeComponent();
 20         }
 21 
 22         private void Form1_Load(object sender, EventArgs e)
 23         {
 24 
 25         }
 26 
 27         public string file_name;
 28         private void button1_Click(object sender, EventArgs e)
 29         {
 30             try
 31             {
 32                 label3.Text = String.Empty;
 33                 OpenFileDialog openTxtDialog = new OpenFileDialog();
 34                 openTxtDialog.Filter = "Points Files (*.txt;*.csv)|*.txt;*.csv";
 35                 openTxtDialog.Multiselect = false;
 36                 openTxtDialog.RestoreDirectory = true;
 37                 if (openTxtDialog.ShowDialog() == DialogResult.OK)
 38                 {
 39                     label3.Text = openTxtDialog.FileName;
 40                     file_name = openTxtDialog.FileName.ToString();
 41                 }
 42             }
 43             catch
 44             {
 45                 MessageBox.Show("文件导入出错,请重新导入!");
 46                 label3.Text = String.Empty;
 47             }
 48         }
 49 
 50         //读取数据,保存点坐标到列表中,原始数据点遁去后保存的地方是叫 POINT_XYZ 的列表
 51         public List<double> Read_Point()
 52         {
 53             List<double> POINT_XYZ = new List<double>();
 54             FileStream stream = new FileStream(file_name, FileMode.Open);
 55             StreamReader reader = new StreamReader(stream);
 56             string[] Start_End = reader.ReadToEnd().Split(new char[3] { '\r', '\n', ' ' });
 57             Start_End = Start_End.Where(s => !string.IsNullOrEmpty(s)).ToArray();     //去除空字符串
 58             reader.Close();
 59             stream.Close();
 60             for (int i = 0; i < Start_End.ToArray().Length; i++)
 61             {
 62                 POINT_XYZ.Add(Convert.ToDouble(Start_End[i]));
 63             }
 64             return POINT_XYZ;
 65         }
 66 
 67         // 坐标处理
 68         public static int cut_number = 10;
 69         public Dictionary<string, List<double>> Select_Point()
 70         {
 71             List<double> POINT_XYZ = Read_Point();
 72             List<double> POINT_X = new List<double>();
 73             List<double> POINT_Y = new List<double>();
 74             List<double> POINT_Z = new List<double>();
 75             List<double> new_point_x = new List<double>();
 76             List<double> new_point_y = new List<double>();
 77             Dictionary<string, List<double>> new_xyz = new Dictionary<string, List<double>>();
 78             //分离源数据X、Y、Z坐标,分别存进字典
 79             for (int i = 0; i < POINT_XYZ.ToArray().Length; i += 3)
 80             {
 81                 POINT_X.Add(POINT_XYZ[i]);
 82                 POINT_Y.Add(POINT_XYZ[i + 1]);
 83                 POINT_Z.Add(POINT_XYZ[i + 2]);
 84             }
 85             new_xyz.Add("org_point_x", POINT_X);
 86             new_xyz.Add("org_point_y", POINT_Y);
 87             new_xyz.Add("org_point_z", POINT_Z);
 88             double width_panel = this.panel1.Width - 60;
 89             double height_panel = this.panel1.Height - 60;
 90             double width_grid = POINT_X.Max() - POINT_X.Min();
 91             double height_grid = POINT_Y.Max() - POINT_Y.Min();
 92             List<double> DrawGrid_X = new List<double>();
 93             List<double> DrawGrid_Y = new List<double>();
 94             Dictionary<string, List<double>> DrawGrid_XY = new Dictionary<string, List<double>>();
 95             double grid_cut_xx = width_panel / cut_number;
 96             double grid_cut_yy = height_panel / cut_number;
 97             double start_x = 20.0;
 98             double start_y = 15.0;
 99             for (int i = 0; i < cut_number; i++)
100             {
101                 DrawGrid_X.Add(start_x + i * grid_cut_xx);
102             }
103             for (int j = 0; j < cut_number; j++)
104             {
105                 DrawGrid_Y.Add(start_y + j * grid_cut_yy);
106             }
107             DrawGrid_XY.Add("X", DrawGrid_X);
108             DrawGrid_XY.Add("Y", DrawGrid_Y);
109             return DrawGrid_XY;
110         }
111 
112         //控制panel画布的显示与隐藏
113         private void button2_Click_1(object sender, EventArgs e)
114         {
115             //用户是否误触按钮
116             try
117             {
118                 panel1.Visible = true;
119                 Graphics g = panel1.CreateGraphics();
120                 Dictionary<string, List<double>> NEW_XY = Select_Point();
121                 NEW_XY = Select_Point();
122                 Pen pen = new Pen(Color.Red, (float)2);
123                 g.Clear(Color.White);
124                 Font font = new Font("Arial", 9, FontStyle.Regular);
125                 Pen framePen = new Pen(Color.Blue, 1);
126                 int leftX = 60; //最左边的纵线距离图像左边的距离
127                 // 画纵线
128                 for (int i = 0; i < NEW_XY["X"].ToArray().Length; i++)
129                 {
130                     g.DrawLine(framePen, leftX, 50, leftX, this.panel1.Height - 32);
131                     leftX += (this.panel1.Width - 60 - 50) / 9;
132                 }
133                 int topY = 50; //最上边的横线距离图像顶部的距离
134                 // 画横线
135                 for (int i = 0; i < NEW_XY["Y"].ToArray().Length; i++)
136                 {
137                     g.DrawLine(framePen, 60, topY, this.panel1.Width - 56, topY);
138                     topY += (this.panel1.Height - 50 - 30) / 9;
139                 }
140                 g.DrawLine(framePen, 60, topY, this.panel1.Width - 56, topY); //最底下的横线
141             }
142             catch (Exception x)
143             {
144                 Console.WriteLine(x.ToString());
145             }
146 
147         }
148 
149         public double Zp;
150         private void button4_Click(object sender, EventArgs e)
151         {
152             List<double> r = new List<double>();
153             r = Read_Point();
154             double d2;
155             double L;
156             double sum;
157             double W_X = double.Parse(textBox1.Text);
158             double W_Y = double.Parse(textBox2.Text);
159             List<double> Z = new List<double>();
160             for (int i = 0; i < r.ToArray().Length / 3; i += 2)
161             {
162                 //计算距离,每一个离散点至目标点的平面距离
163                 for (int j = 0; j < r.ToArray().Length / 3; j++)
164                 {
165                     d2 = Math.Pow((W_X - r[j]), 2) + Math.Pow((W_Y - r[j + 1]), 2);
166                     L = 1 / d2;
167                     sum = r[i + 2] / d2;
168                 }
169             }
170             for (int i = 0; i < r.ToArray().Length / 3; i++)
171             {
172                 Z.Add(r[i + 2]);
173             }
174             Zp = Z.Sum() / (double)Z.ToArray().Length;
175             MessageBox.Show("高程差值成功,请进行下一步!");
176         }
177 
178         // 计算填挖方量
179         public double Vol_Wa;
180         public double Vol_Tian;
181         private void button5_Click(object sender, EventArgs e)
182         {
183             double width_panel = this.panel1.Width - 60;
184             double height_panel = this.panel1.Height - 60;
185             double grid_cut_xx = width_panel / cut_number;
186             double grid_cut_yy = height_panel / cut_number;
187 
188             if (checkBox1.Checked)
189             {
190                 Vol_Wa = Math.Round(grid_cut_xx * grid_cut_xx / 4 * (Zp * 4), 4);
191                 Vol_Tian = Math.Round(grid_cut_yy * grid_cut_yy / 4 * (Zp * 4), 4);
192                 label8.Text = Convert.ToString(Math.Abs(Vol_Wa));
193                 label9.Text = Convert.ToString(Math.Abs(Vol_Tian));
194             }
195 
196             if (checkBox2.Checked)
197             {
198                 Vol_Wa = Math.Round(grid_cut_xx * grid_cut_xx / 4 * ((Zp * Zp / (Zp * 2)) * 2), 4);
199                 Vol_Tian = Math.Round(grid_cut_yy * grid_cut_yy / 4 * ((Zp * Zp / (Zp * 2)) * 2), 4);
200                 label8.Text = Convert.ToString(Math.Abs(Vol_Wa));
201                 label9.Text = Convert.ToString(Math.Abs(Vol_Tian));
202             }
203 
204             if (checkBox3.Checked)
205             {
206                 Vol_Wa = Math.Round((grid_cut_xx * grid_cut_xx / 6 * ((Zp * Zp) / (6 * 4 * Zp * Zp))), 4);
207                 Vol_Tian = Math.Round(grid_cut_yy * grid_cut_yy / 6 * (2 * Zp) + Vol_Wa, 4);
208                 label8.Text = Convert.ToString(Math.Abs(Vol_Wa));
209                 label9.Text = Convert.ToString(Math.Abs(Vol_Tian));
210             }
211             if (checkBox4.Checked)
212             {
213                 Vol_Wa = Math.Round(grid_cut_xx * grid_cut_xx / 4 * (Zp * 4), 4);
214                 Vol_Tian = Math.Round(grid_cut_xx * grid_cut_xx / 4 * (Zp * 4), 4);
215                 label8.Text = Convert.ToString(Math.Abs(Vol_Wa));
216                 label9.Text = Convert.ToString(Math.Abs(Vol_Tian));
217             }
218         }219     }
220 }

 

格网点高程内插用反距离加权法,公式如下:

                                                        1

式中,Zi Zp 分别为第i 个参考点和待插点p 的高程值,n 为参考点个数,di 为参考点到待插值之间的距离。

 

2. 填挖方计算

1)方格四个角点全部为填土式挖方,其土方量:

                                         2

注:为角点填方高度,为绝对值。

2)方格的相邻两角点为挖方,另两角点为填方。

其挖方部分工程量:

                                      3

其填方部分工程量:

                                      4

注:为需挖方角点挖方高度,为需填方角点填方高度。皆为绝对值。

3)方格的三个角点为挖方,另一个角点为填方。

其填方部分工程量:

                                     5

其挖方部分工程量:

                                     6

注:为需挖方角点挖方高度,为需填方角点填方高度。皆为绝对值。

4)方格的一个角点为挖方,相对的角点为填方。另两个角点为零点时(零线为方格的对角线),其挖填方工程量为:

      

你可能感兴趣的:(格网体积计算)