性能需求
(1)硬件需求:这一软件是开发在个人电脑上的,并且运行也需要在电脑上。其中为保证运行顺畅,CPU最好在i5以上或者AMD 锐龙5,内存最好在4G以上,显卡NVIDIA GeForce MX110即可,存储空间300M。
(2)软件需求:这一软件在Windows下面开发,开发环境是Visual Studio2017,开发语言是C#.NET。故运行也需要在Windows下进行,并且电脑安装有Visual Studio2013及以上版本,其中C#.NET的框架是.NET Framework 4.6.1。对于数据库要求,需要安装SQL sever2016及以上版本,确保数据库运行。
功能需求
日前,我国的北斗全球卫星定位系统已经完成全球组网。这标志着我国拥有了自己的卫星定位系统。如何利用卫星进行精确定位是一项重要课题。这一软件从卫星定位原理出发,简单地实现了通过卫星的星历数据,计算卫星坐标,通过单点定位的方法,求得地面待测点的三维坐标。 这一软件的功能如上图1-1所示,包括读取卫星的广播星历文件,通过星历计算卫星某一时刻的三维坐标,批量时刻点和多颗卫星计算,以及通过单点定位的方法实现对地面点进行三维坐标测算。
功能模块设计
文件读取模块
数据原始文件是从IGS官网(网址:http://garner.ucsd.edu/pub/nav/)下载得到的广播星历文件用来计算卫星坐标,从相关网站上(网址:http://garner.ucsd.edu/pub/misc/BatCaves/0001024c.06o)下载了单点定位要用的观测值文件。文件编码格式采用的是UTF-8的格式。故而直接编写读取文件的程序将其读进来,并把他们中用于计算的参数存入到卫星参数数据库中。在卫星参数数据库里,每一行代表某一个卫星在某时刻的各个参数。在参数分割中,需要处理广播星历的文件,如图2-2所示。其中“END OF HEADER”以上的信息是星历信息,在本题中不需要,故需要从“END OF HEADER”下面开始搜索有用信息。例如要求计算2008年5月14日02点0分00秒—20分00秒,每隔1分钟的PRN2的坐标的轨道坐标,只需提取第一列是2(卫星号),对应行是“08 5 14 2 0”(对应时间)即可。
卫星坐标计算模块
单点定位计算模块
类设计
对于这一程序,我设计了五个类,其中两个计算类,分别用于计算卫星坐标和单点定位坐标求解。三个数据库操作类,DataBase是基类,包含数据库的基本操作:查找、显示、删除、添加、修改等,派生出两个子类用于处理卫星坐标数据库和地面点坐标数据库。
详细设计
文件读取模块设计
对于文件读取,我大致在程序中分为了三个步骤:打开文件,切割字符串和将参数存入到数据库。 在打开文件中我使用了openfiledialog对话框,以便在提示下打开要用的文件,并将文件中的内容读入到字符串中。
OpenFileDialog pdlg
= new OpenFileDialog();
pdlg
.Filter
= "所有文件|*.*";
DialogResult rt
= pdlg
.ShowDialog();
if (rt
== DialogResult
.OK
)
{
string filename
= pdlg
.FileName
;
info
= File
.ReadAllLines(filename
);
}
在切割字符串过程中,根据2.1.1所介绍的规则进行分割,此处由于数据并不是严格以空格或者其他方式分隔,所以,我利用正则表达式将有用的数据提取出来。
for (ii
= 0; ii
< row
-1; ii
++)
{
find
= info
[ii
];
find
= find
.Trim();
if (find
== "END OF HEADER")
break;
}
for(ii
=ii
+1;ii
<row
;ii
=ii
+8)
{
Canshu canshu
;
int i
= ii
;
string iline
=info
[i
];
Regex re
= new Regex(@"(\d+(\.\d+)?)");
MatchCollection iarray
= re
.Matches(iline
);
double[,] all
= new double[7, 4];
string[] starray
= new string[7]; int m
= 0;
for (int k
= i
+ 1; k
< i
+ 8; k
++, m
++)
{
iline
= info
[k
];
starray
[m
] = iline
;
}
string stallof
= "";
foreach (string strs
in starray
)
{
stallof
= stallof
+ strs
;
}
Regex p
= new Regex(@"(-??\d?[.]\d{12}['D'][+-]\d\d)");
MatchCollection collection
= p
.Matches(stallof
);
double[] alls
= new double[28];
for (int n
= 0; n
< 25; n
++)
{
string[] temst
= collection
[n
].Value
.Split('D');
alls
[n
] = double.Parse(temst
[0]) * Math
.Pow(10, double.Parse(temst
[1]));
}
卫星坐标计算模块设计
对于卫星坐标计算,我设计了一个计算类,通过有参数的构造函数把对应的卫星序号和时间传进来进行计算。计算中我分为了两类:一类是根据星历可以直接求得的卫星坐标,这种坐标是精度比较高的;一类是需要根据星历求得临近时刻的卫星坐标,这种坐标精度低一些。这两类首先都需要先把输入的时间转换为对应的GPS周秒形式。
对于第一类卫星,直接通过从卫星参数数据库找到相应值,根据2.1.2介绍的原理,计算卫星三维坐标。
对于第二类卫星坐标的求解,我们需要先判断这一卫星距离哪一个通过星历计算出的位置近,并取这一星历数据作为起算数据,后续过程与第一类大致相同。
数据库模块设计
在数据库设计中,我利用类的继承与重写等面向对象的机制,设计了一个父类,两个子类,实现对卫星参数数据库、卫星坐标数据库和地面坐标数据库的管理。在数据库的类中,利用构造函数连接数据库,这样只要调用时就可以自动连接。
对于查找操作,通过连接数据库,向SQL中传入查询语句,并将返回值保存到DataSet类型中,最后通过窗体台中的DataGridView控件显示查找值。
单点定位计算模块设计
对于单点定位的程序设计,大致根据2.1.3介绍的数学模型进行设计。首先先判断卫星数与4比的大小。如果大于4,则需要用最小二乘求解改正值;如果等于4,则利用线性方程直接求解;如果小于4,则无法计算。过程中需要矩阵的运算,在这里我运用了之前写过的矩阵运算类解决求逆,转置等问题。
界面设计
对于这一程序,我选择了如图3-1所示的单文档界面,通过tabControl控件,把“查看修改卫星参数”、“卫星坐标计算与查看”、“单点定位”分隔开,让每一个成单独的部分。在每一部分中,使用splitContainer把页面隔成输入输出两个模块,其中,由于在第一部分的输入类型有多种,故使用GroupBox控件分组管理。这一界面设计方式能够减少文件窗口,操作简单,而且可读性可观性较好。
首先是标签栏设计。如图所示,通过“文件->打开”,可以实现打开文件操作。通过“文件->分割字符串”可以实现分割字符串,从文件内容中提取有用的参数,并存入到内存中。通过“文件->参数装入数据库”可实现把内存中的参数集合存入到卫星参数数据库中,方便之后的步骤使用。通过“文件->保存为文本文档”可以实现把卫星坐标的内容存为文本文件,方便之后精度对比。
对于第一页,都涉及通过界面输入向内部传值,此过程涉及到字符串分割,尤其是使用dateTimePicker控件中的值,先需要通过ToShortDateString和ToLongTimeString把时间转换成字符串格式,通过字符串切割取出时间参数。在修改模块中,运用comBox控件,实现让用户通过下拉列表选择修改的属性。
对于第二页卫星坐标计算与查看,如图3-3和3-4所示,利用radioButton控件选择计算类型,从而选择对应的函数进行调用。在这一过程中,为了增强程序的健壮性,提升容错能力,当用户没有勾选计算类型的时候,会弹出如图3-5的输入警示图;当用户有一些必要参数没有输入的时候,会弹出如图3-6的警示图。在计算完成后,结果会显示在下方的DataGridView控件中,其中多卫星多时刻计算时,输出的结果是每隔一分钟输出一个卫星坐标。
对于第三页,如图3-6所示,通过DateTimePick控件实现选择观测的日期和时间,并通过textbox输入近似值的坐标,即可通过调用计算类方法计算出该地面点的三维坐标,最终将结果输入到地面点数据库和DataGridView控件中。
调试分析与测试结果
文件读取功能模块调试分析
本程序读取的文件是卫星的广播星历,文件编码格式是“utf-8”,文件的后缀是.XXn,其中XX代表年份,n表示广播星历,例如本测试数据文件后缀是:.08n代表是2008年的广播星历数据。这一数据来源是从IGS网站下载得来。 在切割字符串后弹出如图4-1所示的提示框,说明切割成功。如图4-2所示是参数装入SQL sever中的显示,由此可知,数据入库成功。
卫星坐标计算模块调试分析
如图4-3是对星历文件中包含的卫星指定时刻的卫星坐标计算。我们可以通过直接把结果与精密星历对比。拿2008年5月14日2时0分0秒做对比,结果如表4-1。 如表4-1所示,我们可以看到通过广播星历计算得到的坐标值与精密星历之间的误差在米级,符合精度的要求,所以本程序测试通过。
批量时刻点和多颗卫星计算。我们可以利用之前的精密星历与各个计算结果进行比较绘制出如图4-5所示的误差图。 我利用python语言,把通过精密星历得到的坐标作为标准坐标,与通过广播星历得到的坐标做中误差计算。并分别绘制了两颗卫星,不同时刻的点位中误差图,我们发现,其误差在米级,符合规定要求,因此测试通过。
数据库模块调试分析
查看功能:在输入框内输入测试值,查询结果如图4-6所示。可以看到我们可以显示出这一条信息的数值。 修改功能:在输入框内输入修改的地方,选择修改的属性,输入修改后的值,修改结果如图4-7所示,我们可以看到这一条信息的“crs”值已被修改。 删除功能:在输入框内输入删除的地方,删除结果如图4-7所示,我们可以看到,当再次执行查看操作时,删除的那一条信息已经没有了,由此删除成功。
操作使用说明
在第一次处理某一星历的时候,需要首先打开文件(文件->打开),接着切割字符串(文件->分割字符串),等到弹出“OK”对话框后,再把参数存入数据库(文件->参数装入数据库)。这时,我们可以点击“查看”按钮浏览一下分割后的结果。
这一程序有三个板块。第一个板块是对已经得到的卫星参数数据库做查看,修改,删除操作。实现灵活处理数据库的功能。 单击“卫星坐标计算与查看”进入第二板块,可以点击单卫星计算,输入卫星序号和时间,可以直接计算并显示出该点的三维坐标,并存入到数据库中,作为计算日志。如图5-2 单卫星计算图。当点击多卫星多时刻计算时,在卫星序号输入栏里输入卫星号,并用逗号隔开,在时间栏里输入起止时间,点击计算,将会输出每隔一分钟的卫星坐标,如图5-3 多卫星多时刻计算图。在计算完成后还可以通过“文件->保存为文本文档”将计算查询结果保存为文本文件,这实现了数据文件存储和数据库存储双重存储。
最后,点击“单点定位”进入第三板块,如图5-4 单点定位窗口图,通过选择日期和时间,输入测站的近似坐标,单击单点定位,即可通过搜索可用的卫星星历,计算可视的卫星坐标,进而得到地面点坐标,最终保存并显示到下方表格中。
代码
类代码
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
using System
.Data
.SqlClient
;
using System
.Data
;
using MathNet
.Numerics
.LinearAlgebra
.Double
;
using MathNet
.Numerics
.LinearAlgebra
;
namespace GPS卫星坐标与单点定位计算
{
public struct Canshu
{
public double a
, dn
, to
, mo
, e
, omega
, gpsweek
;
public double cuc
, cus
, crc
, crs
, cic
, cis
, idot
, io
, OMEGA
, OMEGA_DOT
;
public int prn
, year
, month
, day
, hour
, minute
;
public double second
;
}
public struct XYZ
{
public double X
, Y
, Z
;
}
public struct Inputdata
{
public double second
, X
, Y
, Z
;
public int prn
, year
, month
, day
, hour
, minute
;
}
class SatelliteCoordinate
{
int year
, month
, day
, hour
, minute
;
double second
;
public SatelliteCoordinate(int year
, int month
, int day
, int hour
, int minute
, double second
)
{
this.year
= year
;
this.month
= month
;
this.day
= day
;
this.hour
= hour
;
this.minute
= minute
;
this.second
= second
;
}
private int GetGPSTime( ref int weekno
, ref double gpstime
)
{
int dayofw
, dayofy
, yr
, ttlday
, m
;
int[] dinmth
= new int[13];
dinmth
[1] = 31; dinmth
[2] = 28; dinmth
[3] = 31;
dinmth
[4] = 30; dinmth
[5] = 31; dinmth
[6] = 30;
dinmth
[7] = 31; dinmth
[8] = 31; dinmth
[9] = 30;
dinmth
[10] = 31; dinmth
[11] = 30; dinmth
[12] = 31;
if (year
> 80) year
= year
+ 1900;
if (year
< 80) year
= year
+ 2000;
if (year
< 1981 || month
< 1 || month
> 12 || day
< 1 || day
> 31)
weekno
= 0;
if (month
== 1)
dayofy
= day
;
else
{
dayofy
= 0;
for (m
= 1; m
<= (month
- 1); m
++)
{
dayofy
+= dinmth
[m
];
if (m
== 2)
{
if (year
% 4 == 0 && year
% 100 != 0 || year
% 400 == 0)
dayofy
+= 1;
}
}
dayofy
+= day
;
}
ttlday
= 360;
for (yr
= 1981; yr
<= (year
- 1); yr
++)
{
ttlday
+= 365;
if (yr
% 4 == 0 && yr
% 100 != 0 || yr
% 400 == 0)
ttlday
+= 1;
}
ttlday
+= dayofy
;
weekno
= ttlday
/ 7;
dayofw
= ttlday
- 7 * (weekno
);
gpstime
= (double)(hour
* 3600 + minute
* 60 + second
+ dayofw
* 86400);
return yr
;
}
private XYZ caculate(Canshu canshu
)
{
int weekno
=0;double gpst
=0.0;
GetGPSTime(ref weekno
, ref gpst
);
double gm
= 3.978655e
+14;
double ve
= 7.2921151467e
-5;
XYZ xyz
; xyz
.X
= xyz
.Y
= xyz
.Z
= 0;
double n
= Math
.Sqrt(gm
/ Math
.Pow(canshu
.a
, 3)) + canshu
.dn
;
double tk
= gpst
- canshu
.to
;
double mk
= canshu
.mo
+ n
* tk
;
double ek0
= canshu
.mo
; double ek1
= 0.0;
while (Math
.Abs(ek0
- ek1
) > 0.0000000001)
{
ek1
= ek0
;
ek0
= canshu
.mo
+ canshu
.e
* Math
.Sin(ek0
);
}
double vk
= Math
.Atan(Math
.Sqrt(1 - canshu
.e
* canshu
.e
) * Math
.Sin(ek1
) / (Math
.Cos(ek1
) - canshu
.e
));
double fei
= vk
+ canshu
.omega
;
double rk
= canshu
.a
* (1 - canshu
.e
* Math
.Cos(ek1
));
double stu
= canshu
.cuc
* Math
.Cos(2 * fei
) + canshu
.cus
* Math
.Sin(2 * fei
);
double str
= canshu
.crc
* Math
.Cos(2 * fei
) + canshu
.crs
* Math
.Sin(2 * fei
);
double sti
= canshu
.cic
* Math
.Cos(2 * fei
) + canshu
.cis
* Math
.Sin(2 * fei
);
double uk
= fei
+ stu
;
double ik
= canshu
.io
+ sti
+ canshu
.idot
* tk
;
rk
= rk
+ str
;
double xk
= rk
* Math
.Cos(uk
);
double yk
= rk
* Math
.Sin(uk
);
double OMEGAk
= canshu
.OMEGA
+ tk
* (canshu
.OMEGA_DOT
- ve
) - ve
* canshu
.to
;
xyz
.X
= xk
* Math
.Cos(OMEGAk
) - yk
* Math
.Cos(ik
) * Math
.Sin(OMEGAk
);
xyz
.Y
= xk
* Math
.Sin(OMEGAk
) + yk
* Math
.Cos(ik
) * Math
.Cos(OMEGAk
);
xyz
.Z
= yk
* Math
.Sin(ik
);
return xyz
;
}
public DataSet EphemerisCac(string sprns
)
{
DataBase db
= new DataBase();
string sql
= "select * from wxc where (" + " prn= " + sprns
+ " and year = " + year
+ " and month = " + month
+ " and day = " + day
+ " and hour = " + hour
+ " and minute = " + minute
+ " and second = " + second
+ " )";
DataSet ds
= new DataSet();
db
.SearchDatabase(sql
, ref ds
);
List
<string> scs
= new List<string>();
foreach (DataRow dr
in ds
.Tables
[0].Rows
)
{
foreach (DataColumn dc
in ds
.Tables
[0].Columns
)
scs
.Add(dr
[dc
].ToString());
}
#region
Canshu canshu
= new Canshu();
canshu
.prn
= int.Parse(scs
[0]);
canshu
.year
= int.Parse(scs
[1]);
canshu
.month
= int.Parse(scs
[2]);
canshu
.day
= int.Parse(scs
[3]);
canshu
.hour
= int.Parse(scs
[4]);
canshu
.minute
= int.Parse(scs
[5]);
canshu
.second
= double.Parse(scs
[6]);
canshu
.a
= double.Parse(scs
[7]);
canshu
.dn
= double.Parse(scs
[8]);
canshu
.to
= double.Parse(scs
[9]);
canshu
.mo
= double.Parse(scs
[10]);
canshu
.e
= double.Parse(scs
[11]);
canshu
.omega
= double.Parse(scs
[12]);
canshu
.cuc
= double.Parse(scs
[13]);
canshu
.cus
= double.Parse(scs
[14]);
canshu
.crc
= double.Parse(scs
[15]);
canshu
.crs
= double.Parse(scs
[16]);
canshu
.cic
= double.Parse(scs
[17]);
canshu
.cis
= double.Parse(scs
[18]);
canshu
.idot
= double.Parse(scs
[19]);
canshu
.io
= double.Parse(scs
[20]);
canshu
.OMEGA
= double.Parse(scs
[21]);
canshu
.OMEGA_DOT
= double.Parse(scs
[22]);
#endregion
XYZ xYZ
= caculate(canshu
);
XyzDatabase db2
= new XyzDatabase();
db2
.InsertDatabase(xYZ
, canshu
);
DataSet ds2
= new DataSet();
string pre
= " Where ( prn= " + scs
[0] + " and year = " + scs
[1] + " and month = " + scs
[2] + " and day = " + scs
[3] + " and hour =" + scs
[4] + " and minute = " + scs
[5] + " and second = " + scs
[6]+")";
db2
.WatchDatabase(ref ds2
, "xyz",pre
);
return ds2
;
}
public Inputdata CoordinateCac(string sprns
)
{
DataSet ds
= new DataSet();
DataBase db
= new DataBase();
string sql
= "select * from wxc where ( prn =" + sprns
+ " and year = " + year
.ToString() + " and month = " + month
.ToString() + " and day = " + day
.ToString() + " )";
DataSet ds0
= new DataSet();
db
.SearchDatabase(sql
, ref ds0
);
double mintime
=90000;int minidex
=0;
for(int i
=0;i
<ds0
.Tables
[0].Rows
.Count
;i
++)
{
int chour
= int.Parse(ds0
.Tables
[0].Rows
[i
][4].ToString());
int cminute
= int.Parse(ds0
.Tables
[0].Rows
[i
][5].ToString());
double csecond
= double.Parse(ds0
.Tables
[0].Rows
[i
][5].ToString());
double time
= Math
.Abs(chour
- hour
) * 3600 + Math
.Abs(cminute
- minute
) * 60 + Math
.Abs(csecond
- second
);
if(time
< mintime
)
{
minidex
= i
;
mintime
= time
;
}
}
#region
Canshu canshu
= new Canshu();
canshu
.prn
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][0].ToString());
canshu
.year
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][1].ToString());
canshu
.month
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][2].ToString());
canshu
.day
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][3].ToString());
canshu
.hour
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][4].ToString());
canshu
.minute
= int.Parse(ds0
.Tables
[0].Rows
[minidex
][5].ToString());
canshu
.second
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][6].ToString());
canshu
.a
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][7].ToString());
canshu
.dn
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][8].ToString());
canshu
.to
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][9].ToString());
canshu
.mo
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][10].ToString());
canshu
.e
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][11].ToString());
canshu
.omega
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][12].ToString());
canshu
.cuc
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][13].ToString());
canshu
.cus
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][14].ToString());
canshu
.crc
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][15].ToString());
canshu
.crs
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][16].ToString());
canshu
.cic
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][17].ToString());
canshu
.cis
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][18].ToString());
canshu
.idot
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][19].ToString());
canshu
.io
=double.Parse(ds0
.Tables
[0].Rows
[minidex
][20].ToString());
canshu
.OMEGA
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][21].ToString());
canshu
.OMEGA_DOT
= double.Parse(ds0
.Tables
[0].Rows
[minidex
][22].ToString());
#endregion
XYZ xYZ
= caculate(canshu
);
XyzDatabase db2
= new XyzDatabase();
Inputdata ida
= new Inputdata();
ida
.X
= xYZ
.X
;
ida
.Y
= xYZ
.Y
;
ida
.Z
= xYZ
.Z
;
ida
.prn
= canshu
.prn
;
ida
.year
= year
;
ida
.minute
= minute
;
ida
.month
= month
;
ida
.day
= day
;
ida
.hour
= hour
;
ida
.second
= second
;
db2
.InsertDatabase(ida
);
return ida
;
}
}
class DataBase
{
SqlConnection myconnection
= new SqlConnection();
public DataBase()
{
string a
= "Data Source=DESKTOP-PNEN86K;Initial Catalog=canshu;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;max pool size=30000";
myconnection
.ConnectionString
= a
;
myconnection
.Open();
}
public DataBase(string catalog
)
{
string a
= "Data Source=DESKTOP-PNEN86K;Initial Catalog="+catalog
+";Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
myconnection
.ConnectionString
= a
;
myconnection
.Open();
}
public void InsertDatabase(Canshu canshu
)
{
if (myconnection
.State
== System
.Data
.ConnectionState
.Open
)
{
string prns
= canshu
.prn
.ToString();
string year
= canshu
.year
.ToString();
string month
= canshu
.month
.ToString();
string day
= canshu
.day
.ToString();
string hour
= canshu
.hour
.ToString();
string minute
= canshu
.minute
.ToString();
string second
= canshu
.second
.ToString();
string a
= canshu
.a
.ToString();
string dn
= canshu
.dn
.ToString();
string t0
= canshu
.to
.ToString();
string m0
= canshu
.mo
.ToString();
string e
= canshu
.e
.ToString();
string omega
= canshu
.omega
.ToString();
string cuc
= canshu
.cuc
.ToString();
string cus
= canshu
.cus
.ToString();
string crc
= canshu
.crc
.ToString();
string crs
= canshu
.crs
.ToString();
string cic
= canshu
.cic
.ToString();
string cis
= canshu
.cis
.ToString();
string idot
= canshu
.idot
.ToString();
string i0
= canshu
.io
.ToString();
string bigomega
= canshu
.OMEGA
.ToString();
string bigomegadot
= canshu
.OMEGA_DOT
.ToString();
string col
= "prn,year,month,day,hour,minute,second,a,dn,t0,m0,e,omega,cuc,cus,crc,crs,cic,cis,idot,i0,bigomega,bigomegadot";
string res
= prns
+ "," + year
+ "," + month
+ "," + day
+ "," + hour
+ "," + minute
+ "," + second
+ "," + a
+ "," + dn
+ "," + t0
+ "," + m0
+ "," + e
+ "," + omega
+ "," + cuc
+ "," + cus
+ "," + crc
+ "," + crs
+ "," + cic
+ "," + cis
+ "," + idot
+ "," + i0
+ "," + bigomega
+ "," + bigomegadot
;
string SQL1
= "insert into wxc (" + col
+ ") values(" + res
+ ")";
SqlCommand com
= new SqlCommand(SQL1
, myconnection
);
com
.ExecuteNonQuery();
}
}
public void WatchDatabase(ref DataSet ds
,string biao
="wxc",string pre
= "")
{
DataBase db
= new DataBase();
string SQL2
= "Select * From " + biao
+ pre
;
SqlDataAdapter mydataadapter
= new SqlDataAdapter();
mydataadapter
.SelectCommand
= new SqlCommand(SQL2
, myconnection
);
ds
= new DataSet();
mydataadapter
.Fill(ds
, biao
);
}
public void SearchDatabase(string SQL2
,ref DataSet ds
)
{
DataBase db
= new DataBase();
string biao
= "wxc";
SqlDataAdapter mydataadapter
= new SqlDataAdapter();
mydataadapter
.SelectCommand
= new SqlCommand(SQL2
, myconnection
);
ds
= new DataSet();
mydataadapter
.Fill(ds
, biao
);
}
public DataSet ReviseDatabase(string SQL1
)
{
DataSet ds
= new DataSet();
if (myconnection
.State
==System
.Data
.ConnectionState
.Open
)
{
SqlCommand com
= new SqlCommand(SQL1
, myconnection
);
com
.ExecuteNonQuery();
string SQL2
= "Select * From wxc" ;
SqlDataAdapter mydataadapter
= new SqlDataAdapter();
mydataadapter
.SelectCommand
= new SqlCommand(SQL2
, myconnection
);
mydataadapter
.Fill(ds
, "wxc");
}
return ds
;
}
public DataSet DeleteDatabase(string SQL
)
{
DataSet ds
= new DataSet();
if(myconnection
.State
== System
.Data
.ConnectionState
.Open
)
{
SqlCommand com
= new SqlCommand(SQL
, myconnection
);
com
.ExecuteNonQuery();
string SQL2
= "Select * From wxc";
SqlDataAdapter mydataadapter
= new SqlDataAdapter();
mydataadapter
.SelectCommand
= new SqlCommand(SQL2
, myconnection
);
mydataadapter
.Fill(ds
, "wxc");
}
return ds
;
}
}
class XyzDatabase:DataBase
{
SqlConnection myconnection
= new SqlConnection();
public XyzDatabase()
{
string a
= "Data Source=DESKTOP-PNEN86K;Initial Catalog=canshu;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;max pool size=30000";
myconnection
.ConnectionString
= a
;
myconnection
.Open();
}
public void InsertDatabase(XYZ xYZ
, Canshu canshu
)
{
if (myconnection
.State
== System
.Data
.ConnectionState
.Open
)
{
string sx
= xYZ
.X
.ToString();
string sy
= xYZ
.Y
.ToString();
string sz
= xYZ
.Z
.ToString();
string prns
= canshu
.prn
.ToString();
string year
= canshu
.year
.ToString();
string month
= canshu
.month
.ToString();
string day
= canshu
.day
.ToString();
string hour
= canshu
.hour
.ToString();
string minute
= canshu
.minute
.ToString();
string second
= canshu
.second
.ToString();
string col
= "prn,year,month,day,hour,minute,second,x,y,z";
string res
= prns
+ " , " + year
+ " , " + month
+ " , " + day
+ " , " + hour
+ " , " + minute
+ " , " + second
+ " , " + sx
+ " , " + sy
+ " , " + sz
;
string SQL
= "insert into xyz (" + col
+ " ) values (" + res
+ ")";
SqlCommand com
= new SqlCommand(SQL
, myconnection
);
com
.ExecuteNonQuery();
}
}
public void InsertDatabase(Inputdata ida
)
{
if (myconnection
.State
== System
.Data
.ConnectionState
.Open
)
{
string sx
= ida
.X
.ToString();
string sy
= ida
.Y
.ToString();
string sz
= ida
.Z
.ToString();
string prns
= ida
.prn
.ToString();
string year
= ida
.year
.ToString();
string month
= ida
.month
.ToString();
string day
= ida
.day
.ToString();
string hour
= ida
.hour
.ToString();
string minute
= ida
.minute
.ToString();
string second
= ida
.second
.ToString();
string col
= "prn,year,month,day,hour,minute,second,x,y,z";
string res
= prns
+ " , " + year
+ " , " + month
+ " , " + day
+ " , " + hour
+ " , " + minute
+ " , " + second
+ " , " + sx
+ " , " + sy
+ " , " + sz
;
string SQL
= "insert into xyz (" + col
+ " ) values (" + res
+ ")";
SqlCommand com
= new SqlCommand(SQL
, myconnection
);
com
.ExecuteNonQuery();
}
}
}
class CzDatabase:DataBase
{
SqlConnection myconnection
= new SqlConnection();
public CzDatabase()
{
string a
= "Data Source=DESKTOP-PNEN86K;Initial Catalog=canshu;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;max pool size=30000";
myconnection
.ConnectionString
= a
;
myconnection
.Open();
}
public void InsertDatabase(XYZ xYZ
)
{
if (myconnection
.State
== System
.Data
.ConnectionState
.Open
)
{
string sx
= xYZ
.X
.ToString();
string sy
= xYZ
.Y
.ToString();
string sz
= xYZ
.Z
.ToString();
string col
= "x,y,z";
string res
= sx
+ " , " + sy
+ " , " + sz
;
string SQL
= "insert into cz (" + col
+ " ) values (" + res
+ ")";
SqlCommand com
= new SqlCommand(SQL
, myconnection
);
com
.ExecuteNonQuery();
}
}
}
class SinglePoint
{
private double L0(XYZ xyz0
,XYZ xyzs
)
{
double l0
;
l0
= Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2);
l0
= Math
.Sqrt(l0
);
return l0
;
}
public double[,] singlecac(XYZ xyz0
,List
<XYZ
> xyzlist
)
{
if(xyzlist
.Count
==4)
{
double[,] A
= new double[4,4];
double[,] l0
= new double[4,1];
for(int i
=0;i
<4;i
++)
{
XYZ xyzs
= new XYZ();
xyzs
= xyzlist
[i
];
A
[i
, 0] = -(xyzs
.X
- xyz0
.X
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 1] = -(xyzs
.Y
- xyz0
.Y
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 2] = -(xyzs
.Z
- xyz0
.Z
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 3] = 3E8
;
l0
[i
, 0] = -L0(xyz0
, xyzs
);
}
double[,] x
= new double[4, 1];
x
= Matrix
.MultiplyMatrix(Matrix
.Athwart(A
), l0
);
return x
;
}
else
{
int n
= xyzlist
.Count
;
double[,] A
= new double[n
, n
];
double[,] l0
= new double[n
, 1];
for (int i
= 0; i
<n
; i
++)
{
XYZ xyzs
= new XYZ();
xyzs
= xyzlist
[i
];
A
[i
, 0] = -(xyzs
.X
- xyz0
.X
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 1] = -(xyzs
.Y
- xyz0
.Y
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 2] = -(xyzs
.Z
- xyz0
.Z
) / (Math
.Pow((xyz0
.X
- xyzs
.X
), 2) + Math
.Pow((xyz0
.Y
- xyzs
.Y
), 2) + Math
.Pow((xyz0
.Z
- xyzs
.Z
), 2));
A
[i
, 3] = 3E8
;
l0
[i
, 0] = -L0(xyz0
, xyzs
);
}
double[,] x
= new double[4, 1];
x
= Matrix
.MultiplyMatrix(Matrix
.Athwart((Matrix
.MultiplyMatrix(Matrix
.Transpose(A
), A
))) ,Matrix
.MultiplyMatrix(Matrix
.Transpose(A
),l0
));
return x
;
}
}
}
}
using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace GPS卫星坐标与单点定位计算
{
class Matrix
{
public static double[,] Transpose(double[,] iMatrix
)
{
int row
= iMatrix
.GetLength(0);
int column
= iMatrix
.GetLength(1);
double[,] TempMatrix
= new double[row
, column
];
double[,] iMatrixT
= new double[column
, row
];
for (int i
= 0; i
< row
; i
++)
{
for (int j
= 0; j
< column
; j
++)
{
TempMatrix
[i
, j
] = iMatrix
[i
, j
];
}
}
for (int i
= 0; i
< column
; i
++)
{
for (int j
= 0; j
< row
; j
++)
{
iMatrixT
[i
, j
] = TempMatrix
[j
, i
];
}
}
return iMatrixT
;
}
public static double[,] Athwart(double[,] iMatrix
)
{
int i
= 0;
int row
= iMatrix
.GetLength(0);
double[,] MatrixZwei
= new double[row
, row
* 2];
double[,] iMatrixInv
= new double[row
, row
];
for (i
= 0; i
< row
; i
++)
{
for (int j
= 0; j
< row
; j
++)
{
MatrixZwei
[i
, j
] = iMatrix
[i
, j
];
}
}
for (i
= 0; i
< row
; i
++)
{
for (int j
= row
; j
< row
* 2; j
++)
{
MatrixZwei
[i
, j
] = 0;
if (i
+ row
== j
)
MatrixZwei
[i
, j
] = 1;
}
}
for (i
= 0; i
< row
; i
++)
{
if (MatrixZwei
[i
, i
] != 0)
{
double intTemp
= MatrixZwei
[i
, i
];
for (int j
= 0; j
< row
* 2; j
++)
{
MatrixZwei
[i
, j
] = MatrixZwei
[i
, j
] / intTemp
;
}
}
for (int j
= 0; j
< row
; j
++)
{
if (j
== i
)
continue;
double intTemp
= MatrixZwei
[j
, i
];
for (int k
= 0; k
< row
* 2; k
++)
{
MatrixZwei
[j
, k
] = MatrixZwei
[j
, k
] - MatrixZwei
[i
, k
] * intTemp
;
}
}
}
for (i
= 0; i
< row
; i
++)
{
for (int j
= 0; j
< row
; j
++)
{
iMatrixInv
[i
, j
] = MatrixZwei
[i
, j
+ row
];
}
}
return iMatrixInv
;
}
public static double[,] AddMatrix(double[,] MatrixEin
, double[,] MatrixZwei
)
{
double[,] MatrixResult
= new double[MatrixEin.GetLength(0), MatrixZwei
.GetLength(1)];
for (int i
= 0; i
< MatrixEin
.GetLength(0); i
++)
for (int j
= 0; j
< MatrixZwei
.GetLength(1); j
++)
MatrixResult
[i
, j
] = MatrixEin
[i
, j
] + MatrixZwei
[i
, j
];
return MatrixResult
;
}
public static double[,] SubMatrix(double[,] MatrixEin
, double[,] MatrixZwei
)
{
double[,] MatrixResult
= new double[MatrixEin.GetLength(0), MatrixZwei
.GetLength(1)];
for (int i
= 0; i
< MatrixEin
.GetLength(0); i
++)
for (int j
= 0; j
< MatrixZwei
.GetLength(1); j
++)
MatrixResult
[i
, j
] = MatrixEin
[i
, j
] - MatrixZwei
[i
, j
];
return MatrixResult
;
}
public static double[,] MultiplyMatrix(double[,] MatrixEin
, double[,] MatrixZwei
)
{
double[,] MatrixResult
= new double[MatrixEin.GetLength(0), MatrixZwei
.GetLength(1)];
for (int i
= 0; i
< MatrixEin
.GetLength(0); i
++)
{
for (int j
= 0; j
< MatrixZwei
.GetLength(1); j
++)
{
for (int k
= 0; k
< MatrixEin
.GetLength(1); k
++)
{
MatrixResult
[i
, j
] += MatrixEin
[i
, k
] * MatrixZwei
[k
, j
];
}
}
}
return MatrixResult
;
}
public static double ResultDeterminant(double[,] MatrixEin
)
{
return MatrixEin
[0, 0] * MatrixEin
[1, 1] * MatrixEin
[2, 2] + MatrixEin
[0, 1] * MatrixEin
[1, 2] * MatrixEin
[2, 0] + MatrixEin
[0, 2] * MatrixEin
[1, 0] * MatrixEin
[2, 1]
- MatrixEin
[0, 2] * MatrixEin
[1, 1] * MatrixEin
[2, 0] - MatrixEin
[0, 1] * MatrixEin
[1, 0] * MatrixEin
[2, 2] - MatrixEin
[0, 0] * MatrixEin
[1, 2] * MatrixEin
[2, 1];
}
}
}
窗口代码
using System
;
using System
.Collections
.Generic
;
using System
.ComponentModel
;
using System
.Data
;
using System
.Drawing
;
using System
.Linq
;
using System
.Text
;
using System
.Threading
.Tasks
;
using System
.Windows
.Forms
;
using System
.Data
.SqlClient
;
using System
.Data
;
using System
.IO
;
using System
.Text
.RegularExpressions
;
namespace GPS卫星坐标与单点定位计算
{
public partial class Form1 : Form
{
List
<Canshu
> cslist
= new List<Canshu>();
string[] info
= null;
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender
, EventArgs e
)
{
}
private void splitContainer2_Panel1_Paint(object sender
, PaintEventArgs e
)
{
}
private void 打开
OToolStripMenuItem_Click(object sender
, EventArgs e
)
{
OpenFileDialog pdlg
= new OpenFileDialog();
pdlg
.Filter
= "所有文件|*.*";
DialogResult rt
= pdlg
.ShowDialog();
if (rt
== DialogResult
.OK
)
{
string filename
= pdlg
.FileName
;
info
= File
.ReadAllLines(filename
);
}
}
private void 分割字符串
ToolStripMenuItem_Click(object sender
, EventArgs e
)
{
int row
= info
.Length
;
MessageBox
.Show("共"+row
.ToString()+"条数据");
int ii
= 0;
string find
= "";
for (ii
= 0; ii
< row
-1; ii
++)
{
find
= info
[ii
];
find
= find
.Trim();
if (find
== "END OF HEADER")
break;
}
for(ii
=ii
+1;ii
<row
;ii
=ii
+8)
{
Canshu canshu
;
int i
= ii
;
string iline
=info
[i
];
Regex re
= new Regex(@"(\d+(\.\d+)?)");
MatchCollection iarray
= re
.Matches(iline
);
canshu
.year
= int.Parse(iarray
[1].Value
);
canshu
.month
= int.Parse(iarray
[2].Value
);
canshu
.day
= int.Parse(iarray
[3].Value
);
canshu
.hour
= int.Parse(iarray
[4].Value
);
canshu
.minute
= int.Parse(iarray
[5].Value
);
canshu
.second
= double.Parse(iarray
[6].Value
);
canshu
.prn
= int.Parse(iarray
[0].Value
);
double[,] all
= new double[7, 4];
string[] starray
= new string[7]; int m
= 0;
for (int k
= i
+ 1; k
< i
+ 8; k
++, m
++)
{
iline
= info
[k
];
starray
[m
] = iline
;
}
string stallof
= "";
foreach (string strs
in starray
)
{
stallof
= stallof
+ strs
;
}
Regex p
= new Regex(@"(-??\d?[.]\d{12}['D'][+-]\d\d)");
MatchCollection collection
= p
.Matches(stallof
);
double[] alls
= new double[28];
for (int n
= 0; n
< 25; n
++)
{
string[] temst
= collection
[n
].Value
.Split('D');
alls
[n
] = double.Parse(temst
[0]) * Math
.Pow(10, double.Parse(temst
[1]));
}
for (int a
= 0; a
< 7; a
++)
{
for (int b
= 0; b
< 4; b
++)
all
[a
, b
] = alls
[(4 * a
) + b
];
}
canshu
.a
= Math
.Pow(all
[1, 3], 2);
canshu
.cic
= all
[2, 1];
canshu
.cis
= all
[2, 3];
canshu
.crc
= all
[3, 1];
canshu
.crs
= all
[0, 1];
canshu
.cuc
= all
[1, 0];
canshu
.cus
= all
[1, 2];
canshu
.dn
= all
[0, 2];
canshu
.e
= all
[1, 1];
canshu
.idot
= all
[4, 0];
canshu
.io
= all
[3, 0];
canshu
.mo
= all
[0, 3];
canshu
.omega
= all
[3, 2];
canshu
.OMEGA
= all
[2, 2];
canshu
.to
= all
[2, 0];
canshu
.OMEGA_DOT
= all
[3, 3];
canshu
.gpsweek
= all
[4, 2];
cslist
.Add(canshu
);
}
MessageBox
.Show("ok");
}
private void button1_Click(object sender
, EventArgs e
)
{
if (textBox1
.Text
== "")
{
DataBase db2
= new DataBase();
DataSet ds
= new DataSet();
db2
.WatchDatabase(ref ds
);
dataGridView1
.DataSource
= ds
.Tables
[0];
}
else
{
string sprn
= textBox1
.Text
;
string year
, month
, day
, hour
, minute
, second
;
string date
= dateTimePicker3
.Value
.ToShortDateString();
string[] sd
=date
.Split('/');
year
= sd
[0];
year
= year
.Substring(year
.Length
- 1);
month
= sd
[1];
day
= sd
[2];
string time
= dateTimePicker4
.Value
.ToLongTimeString();
string[] st
= time
.Split(':');
hour
= st
[0];
minute
= st
[1];
second
= st
[2];
DataBase db2
= new DataBase();
DataSet ds
= new DataSet();
string pre
= " Where ( prn = " + sprn
+ " and year = " + year
+ " and month = " + month
+ " and day = " + day
+ " and hour = " + hour
+ " and minute = " + minute
+ " and second = " + second
+ ")";
db2
.WatchDatabase(ref ds
, "wxc", pre
);
dataGridView1
.DataSource
= ds
.Tables
[0];
}
}
private void 参数装入数据库
ToolStripMenuItem_Click(object sender
, EventArgs e
)
{
foreach (Canshu canshu
in cslist
)
{
DataBase db
= new DataBase();
db
.InsertDatabase(canshu
);
}
MessageBox
.Show("ok");
}
private void button2_Click(object sender
, EventArgs e
)
{
bool bool1
= radioButton1
.Checked
;
bool bool2
= radioButton2
.Checked
;
if (bool1
== false && bool2
== false)
{
MessageBox
.Show("请选择计算类型");
}
string y1
, mon1
, d1
, h1
, min1
, s1
, y2
, mon2
, d2
, h2
, min2
, s2
;
y1
= textBox8
.Text
;
mon1
= textBox9
.Text
;
d1
= textBox10
.Text
;
h1
= textBox11
.Text
;
min1
= textBox12
.Text
;
s1
= textBox13
.Text
;
y2
= textBox14
.Text
;
mon2
= textBox15
.Text
;
d2
= textBox16
.Text
;
h2
= textBox17
.Text
;
min2
= textBox18
.Text
;
s2
= textBox19
.Text
;
string sprn
= richTextBox1
.Text
;
string[] sprns
= sprn
.Split(',');
int yp
, monp
, dp
, hp
, minp
, yq
, monq
, dq
, hq
, minq
;
double sp
, sq
;
if (bool1
== true)
{
yp
= int.Parse(y1
);
monp
= int.Parse(mon1
);
dp
= int.Parse(d1
);
hp
= int.Parse(h1
);
minp
= int.Parse(min1
);
sp
= double.Parse(s1
);
SatelliteCoordinate sc
= new SatelliteCoordinate(yp
, monp
, dp
, hp
, minp
, sp
);
DataSet ds2
= new DataSet();
ds2
= sc
.EphemerisCac(sprns
[0]);
dataGridView2
.DataSource
= ds2
.Tables
[0];
}
if (bool2
== true)
{
if (y2
== "" && mon2
== "" && d2
== "" && h2
== "" && min2
== "" && s2
== "")
MessageBox
.Show("请完善参数!");
else
{
yp
= int.Parse(y1
);
monp
= int.Parse(mon1
);
dp
= int.Parse(d1
);
hp
= int.Parse(h1
);
minp
= int.Parse(min1
);
yq
= int.Parse(y2
);
monq
= int.Parse(mon2
);
dq
= int.Parse(d2
);
hq
= int.Parse(h2
);
minq
= int.Parse(min2
);
sp
= double.Parse(s1
);
sq
= double.Parse(s2
);
double dsecond
= (hq
- hp
) * 3600 + (minq
- minp
) * 60;
int count
= Convert
.ToInt32(dsecond
/ 60);
double id
= 0;
for (int i
= 0; i
< count
; i
++, minp
++)
{
for (int j
= 0; j
< sprns
.Length
; j
++)
{
SatelliteCoordinate sc
= new SatelliteCoordinate(yp
, monp
, dp
, hp
, minp
, sp
);
sc
.CoordinateCac(sprns
[j
]);
if (minp
>= 59)
{
hp
= hp
+ 1;
minp
= 0;
}
}
}
DataSet ds
= new DataSet();
DataBase db
= new DataBase();
db
.WatchDatabase(ref ds
, "xyz");
dataGridView2
.DataSource
= ds
.Tables
[0];
}
}
}
private void tabPage2_Click(object sender
, EventArgs e
)
{
}
private void button3_Click(object sender
, EventArgs e
)
{
XYZ xyz0
= new XYZ();
List
<XYZ
> xyzlist
= new List<XYZ>();
double x0
, y0
, z0
;
x0
= double.Parse(textBox20
.Text
);
y0
= double.Parse(textBox21
.Text
);
z0
= double.Parse(textBox22
.Text
);
string year
, month
, day
, hour
, minute
, second
;
string date
= dateTimePicker9
.Value
.ToShortDateString();
string[] sd
= date
.Split('/');
year
= sd
[0];
year
= year
.Substring(year
.Length
- 1);
month
= sd
[1];
day
= sd
[2];
string time
= dateTimePicker1
.Value
.ToLongTimeString();
string[] st
= time
.Split(':');
hour
= st
[0];
minute
= st
[1];
second
= st
[2];
DataBase db2
= new DataBase();
DataSet ds
= new DataSet();
string pre
= " Where ( year = " + year
+ " and month = " + month
+ " and day = " + day
+ " and hour = " + hour
+ " and minute = " + minute
+ " and second = " + second
+ ")";
db2
.WatchDatabase(ref ds
, "wxc", pre
);
List
<Inputdata
> idlist
= new List<Inputdata>();
for(int i
=0;i
< ds
.Tables
[0].Rows
.Count
;i
++)
{
SatelliteCoordinate sc
= new SatelliteCoordinate(int.Parse(year
), int.Parse(month
), int.Parse(day
), int.Parse(hour
), int.Parse(minute
), double.Parse(second
));
string prns
= ds
.Tables
[0].Rows
[i
][0].ToString();
Inputdata ipd
= new Inputdata();
ipd
=sc
.CoordinateCac(prns
);
idlist
.Add(ipd
);
}
for(int i
=0;i
<idlist
.Count
;i
++)
{
xyz0
.X
= idlist
[i
].X
;
xyz0
.Y
= idlist
[i
].Y
;
xyz0
.Z
= idlist
[i
].Z
;
xyzlist
.Add(xyz0
);
}
double[,] x
= new double[4, 1];
SinglePoint sp
= new SinglePoint();
x
= sp
.singlecac(xyz0
, xyzlist
);
XYZ xyz
= new XYZ();
xyz
.X
= x
[0, 0]+x0
;
xyz
.Y
= x
[1,0] + y0
;
xyz
.Z
= x
[2, 0] + z0
;
CzDatabase cdb
= new CzDatabase();
cdb
.InsertDatabase(xyz
);
}
private void button4_Click(object sender
, EventArgs e
)
{
}
private void dateTimePicker1_ValueChanged(object sender
, EventArgs e
)
{
}
private void button5_Click(object sender
, EventArgs e
)
{
string sprn
= textBox2
.Text
;
string year
, month
, day
, hour
, minute
, second
;
string date
= dateTimePicker6
.Value
.ToShortDateString();
string[] sd
= date
.Split('/');
year
= sd
[0];
year
= year
.Substring(year
.Length
- 1);
month
= sd
[1];
day
= sd
[2];
string time
= dateTimePicker5
.Value
.ToLongTimeString();
string[] st
= time
.Split(':');
hour
= st
[0];
minute
= st
[1];
second
= st
[2];
string forms
= comboBox1
.Text
;
string after
= textBox3
.Text
;
DataBase db2
= new DataBase();
DataSet ds
= new DataSet();
string SQL2
= "update wxc set " +forms
+" = "+after
+ " Where ( prn = " + sprn
+ " and year = " + year
+ " and month = " + month
+ " and day = " + day
+ " and hour = " + hour
+ " and minute = " + minute
+ " and second = " + second
+ ")";
ds
=db2
.ReviseDatabase(SQL2
);
dataGridView1
.DataSource
= ds
.Tables
[0];
}
private void button6_Click(object sender
, EventArgs e
)
{
string sprn
= textBox4
.Text
;
string year
, month
, day
, hour
, minute
, second
;
string date
= dateTimePicker7
.Value
.ToShortDateString();
string[] sd
= date
.Split('/');
year
= sd
[0];
year
= year
.Substring(year
.Length
- 1);
month
= sd
[1];
day
= sd
[2];
string time
= dateTimePicker8
.Value
.ToLongTimeString();
string[] st
= time
.Split(':');
hour
= st
[0];
minute
= st
[1];
second
= st
[2];
DataBase db2
= new DataBase();
DataSet ds
= new DataSet();
string sql
="delete from wxc where ( prn =" + sprn
+ " and year = " + year
+ " and month = " + month
+ " and day = " + day
+ " and hour = " + hour
+ " and minute = " + minute
+ " and second = " + second
+ ")";
ds
= db2
.DeleteDatabase(sql
);
dataGridView1
.DataSource
= ds
.Tables
[0];
}
private void 保存为文本文档
ToolStripMenuItem_Click(object sender
, EventArgs e
)
{
string FullFileName
= "D:\\result.txt";
StreamWriter sw
= new StreamWriter(FullFileName
, true, Encoding
.Default
);
string str
= "";
for (int i
= 0; i
< dataGridView2
.Rows
.Count
- 1; i
++)
{
for (int j
= 0; j
< dataGridView2
.Columns
.Count
; j
++)
{
str
= dataGridView2
.Rows
[i
].Cells
[j
].Value
.ToString().Trim();
str
= str
+ " ";
sw
.Write(str
);
}
sw
.WriteLine("");
}
sw
.Close();
}
}
}
SQL建表
use canshubase
go
create table wxc
(
prn
int not null,
year int ,
month int,
day int,
hour int,
minute int,
second float,
a
float,
dn
float,
t0
float,
m0
float,
e
float,
omega
float,
cuc
float,
cus
float,
crc
float,
crs
float,
cic
float,
cis
float,
idot
float,
i0
float,
bigomega
float,
bigomegadot
float,
)
go
use wxcanshu
go
create table xyz
(
prn
int not null,
year int ,
month int,
day int,
hour int,
minute int,
second float,
x
float,
y
float,
z
float,
)
go
use canshu
go
TRUNCATE TABLE xyz
go
select * from xyz
go
create table cz
(
x
float,
y
float,
z
float
)
反思
调试完程序,编写完实习报告。为期五天的测绘编程实习终于告一段落。回顾这五天,时不时通宵修改代码。虽然辛苦,但是也是深有体会。也对自己之后的编程有了一定的教训。 首先之后拿到编程任务的时候不要忙着开始写程序,一定要写理清楚题目要求得的东西,程序要实现的功能,如果有窗体的话,规划窗体如何设计,要设置几个类,类与类之间的关系。把必要的计算过程理顺,绘制出流程图,然后再着手写程序。 编写程序的时候尽量用面向对象的思路设计,一定避免某一个地方好几百行程序,一定要用函数,减少程序的耦合度。一定要减少代码的冗余度,重复的代码一定要放在函数里,最好是封装到类里。 一定要增强程序的健壮性,通过提示,或者增加多种情况讨论来减少由于错误数据传入带来程序的崩掉。在代码编写的过程,一定要加注释,C#在对方法或者类注释的时候在前面打三个“/”就可以产生能够生成一个XML文件的注释形式,这一形式可以在调用的时候有提示。 再有就是对数组,列表等遍历的时候,一定考虑超限的问题。
http://garner.ucsd.edu/pub/ 多数可以匿名登录,用户名:anonymous,密码:自己的Email地址 met 有M文件 nav 有N文件 http://garner.ucsd.edu/pub/misc/BadData/ 有o文件
StarUML类图绘制