博主在前几年写的一个应用程序,用于将NMEA格式的定位数据中的LBH转换为度分秒
NMEA格式如下: 具体每个字段代表的意义可以参考:NMEA格式说明
0001:$GNGGA,055154.00,3954.7885315,N,11615.5569597,E,1,23,0.6,79.9761,M,-9.797,M,,*67
0002:$GNGGA,055155.00,3954.7885325,N,11615.5569457,E,1,23,0.6,80.1820,M,-9.797,M,,*6C
0003:$GNGGA,055156.00,3954.7885010,N,11615.5570199,E,1,23,0.6,80.2369,M,-9.797,M,,*60
0004:$GNGGA,055157.00,3954.7885304,N,11615.5569727,E,1,23,0.6,80.2149,M,-9.797,M,,*6C
0005:$GNGGA,055158.00,3954.7885056,N,11615.5570175,E,1,23,0.6,80.1064,M,-9.797,M,,*63
0006:$GNGGA,055159.00,3954.7885151,N,11615.5570588,E,1,23,0.6,79.9814,M,-9.797,M,,*63
0007:$GNGGA,055200.00,3954.7885596,N,11615.5570476,E,1,23,0.6,80.1273,M,-9.797,M,,*66
0008:$GNGGA,055201.00,3954.7885848,N,11615.5569074,E,1,23,0.6,79.9970,M,-9.797,M,,*61
0009:$GNGGA,055202.00,3954.7885776,N,11615.5569759,E,1,23,0.6,80.0179,M,-9.797,M,,*66
0010:$GNGGA,055203.00,3954.7885262,N,11615.5569545,E,1,23,0.6,80.1997,M,-9.797,M,,*61
0011:$GNGGA,055204.00,3954.7884971,N,11615.5569766,E,1,23,0.6,80.3279,M,-9.797,M,,*64
0012:$GNGGA,055205.00,3954.7885324,N,11615.5569465,E,1,23,0.6,80.2983,M,-9.797,M,,*61
转换后的格式如下:
5.865000 39.913119 116.259283 70.179100 -2167464.937004 4393389.585787 4070636.039359 23.000000 0.600000
5.865278 39.913119 116.259282 70.385002 -2167464.988798 4393389.735866 4070636.171979 23.000000 0.600000
5.865556 39.913119 116.259284 70.439903 -2167465.102553 4393389.727451 4070636.206401 23.000000 0.600000
5.865833 39.913119 116.259283 70.417900 -2167465.034468 4393389.741472 4070636.193087 23.000000 0.600000
5.866111 39.913119 116.259284 70.309402 -2167465.055153 4393389.639102 4070636.122795 23.000000 0.600000
5.866389 39.913119 116.259284 70.184402 -2167465.065515 4393389.527080 4070636.042592 23.000000 0.600000
5.877778 39.913119 116.259284 70.330299 -2167465.100665 4393389.634403 4070636.136330 23.000000 0.600000
5.866944 39.913119 116.259282 70.200005 -2167464.877354 4393389.633332 4070636.052518 23.000000 0.600000
5.867222 39.913119 116.259283 70.220901 -2167464.971909 4393389.604359 4070636.066138 23.000000 0.600000
5.867500 39.913119 116.259283 70.402702 -2167465.006333 4393389.743064 4070636.182574 23.000000 0.600000
5.867778 39.913119 116.259283 70.530907 -2167465.078037 4393389.817222 4070636.264960 23.000000 0.600000
5.868056 39.913119 116.259282 70.501305 -2167465.029571 4393389.815933 4070636.245840 23.000000 0.600000
格式说明如下: 第一列表示时间,单位是h 第二列~第四列表示大地坐标BLH ,经纬度单位为度 ,大地高为m 第五列~第七列表示空间直角坐标XYZ ,单位为m 第八列表示卫星数 第九列表示水平精度因子 源码如下:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define n 1024
#define m 1024
#define a 6378137.00
#define e2 0.00669437999013
#define pi 3.1415926535898
#pragma warning(disable:4996)
typedef struct {
int mode, sig;
double nsat;
float H, dth, dop;
char bsig, lsig, hsig,flag;
double B,time, L;
}line_t;
typedef struct {
int mode, sig;
double nsat;
float H, dth, dop;
char bsig, lsig, hsig, flag;
double B1,Br, time1, L1,Lr, h, min, sec,dd,mm;
double X, Y, Z;
}out_t;
typedef struct {
int y;
char b,c,d,e,f,g;
}num_t;
int main(void)
{
int i = 0,num=0,num1=0;
line_t line[n];
num_t nmr[1024];
out_t output[m];
FILE* fp,*out;
errno_t err,arr;
char filename[50],outfile[50];
printf("请输入原始数据文件名:\n");
scanf_s("%s",filename, 50);
err=fopen_s(&fp,filename , "r");
while (!feof(fp))
{
fscanf(fp,"%4d:%c%c%c%c%c%c,%lf,%lf,%c,%lf,%c,%d,%lf,%f,%f,%c,%f,%c,%s\n",&nmr[i].y, &nmr[i].b, &nmr[i].c, &nmr[i].d, &nmr[i].e, &nmr[i].f, &nmr[i].g,&line[i].time, &line[i].B, &line[i].bsig, &line[i].L, &line[i].lsig, &line[i].mode, &line[i].nsat ,&line[i].dop, &line[i].H, &line[i].hsig, &line[i].dth, &line[i].hsig, &line[i].flag);
i++;
}
int k = i;
printf("请输入输出数据文件名:\n");
scanf_s("%s",outfile,50);
arr = fopen_s(&out, outfile, "w");
for (num = 0; num <k-1; num++)
{
for ( i=num; i <k-1; i++)
{
output[num].B1 = line[i].B+2;
output[num].h = floor((line[i].time/10000));
output[num].min = floor((line[i].time/10000- output[num].h)*100);
output[num].sec = line[i].time - output[num].h * 10000 - output[num].min * 100;
output[num].time1 = output[num].h + ((double)output[num].min) / 60 + (double)output[num].sec/3600;
output[num].B1 = floor(line[i].B / 100) + (line[i].B - (floor(line[i].B / 100) * 100)) / 60;
output[num].L1= floor(line[i].L / 100) + (line[i].L - (floor(line[i].L / 100) * 100)) / 60;
output[num].H = line[i].H + line[i].dth;
output[num].Br = output[num].B1 * (pi / 180);
output[num].Lr= output[num].L1 * (pi / 180);
double N =a/(sqrt(1 - e2*(pow(sin(output[num].Br),2))));
output[num].X = (N+ output[num].H)*cos(output[num].Br)*cos(output[num].Lr);
output[num].Y = (N + output[num].H) * cos(output[num].Br) * sin(output[num].Lr);
output[num].Z = (N*(1-e2)+ output[num].H)* sin(output[num].Br);
output[num].nsat = line[i].nsat;
output[num].dop = line[i].dop;
break;
}
}
for (num1 = 0; num1 <k-1; num1++) {
fprintf(out, "%0.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f %.6f \n", output[num1].time1,output[num1].B1, output[num1].L1, output[num1].H, output[num1].X, output[num1].Y, output[num1].Z, output[num1].nsat, output[num1].dop);
}
puts("\n转换成功!\n");
fclose(fp);
fclose(out);
return EXIT_SUCCESS;
}
也可直接使用应用程序: NMEA转换程序
|