坐标转换源代码--GPS定位程序(C++)
坐标转换从经纬度坐标到大地坐标及源码
坐标转换从经纬度坐标到大地坐标及源码利用网络上开源的资料,可以很容易的实现从经纬度坐标向各种投影坐标的转换,美国地质调查局开发USGS的GCTP就是很好的东西之一,有C语言版本的支持各种投影类型的源代码,比如UNIVERSAL TRANSVERSE MERCATOR, ALBERS CONICAL EQUAL AREA ,LAMBERT CONFORMAL CONIC等等,我们机房使用的就是LAMBERT CONFORMAL CONIC(LAMBERT 圆锥等角投影),利用GCTP提供的源代码详见source文件夹下的lamccfor.c 和 lamccinv.c ,可以轻松实现经纬度投影坐标和LAMBERT CONFORMAL CONIC坐标的相互转化,其他投影方式使用的比较少,还要进一步研究,就以后在写了.lamccforint函数设置LAMBERT CONFORMAL CONIC投影的各个参数,比如长半轴,短半轴,中心点经纬度坐标,标准纬线等等信息.longlamccforint(r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north) double r_maj; /* majoraxis */double r_min; /* minoraxis */double lat1; /* first standardparallel */double lat2; /* second standardparallel */double c_lon; /* centerlongitude */double c_lat; /* centerlatitude */double false_east; /* x offset inmeters */double false_north; /* y offset inmeters */{double sin_po; /* sinvalue */double cos_po; /* cosvalue */double con; /* temporaryvariable */double ms1; /* small m1 */double ms2; /* small m2 */double temp; /* temporaryvariable */double ts0; /* small t0 */double ts1; /* small t1 */double ts2; /* small t2 */r_major = r_maj;r_minor = r_min;false_northing = false_north;false_easting = false_east;/* Standard Parallels cannot be equal and on opposite sides of the equator------------------------------------------------------------------------*/if (fabs(lat1 lat2) < EPSLN){p_error("Equal latitudes for St. Parallels on opposite sides of equator","lamcc-for");return(41);}temp = r_minor / r_major;es = 1.0 - SQUARE(temp);e = sqrt(es);center_lon = c_lon;center_lat = c_lat;sincos(lat1,&sin_po,&cos_po);con = sin_po;ms1 = msfnz(e,sin_po,cos_po);ts1 = tsfnz(e,lat1,sin_po); sincos(lat2,&sin_po,&cos_po);ms2 = msfnz(e,sin_po,cos_po);ts2 = tsfnz(e,lat2,sin_po);sin_po = sin(center_lat);ts0 = tsfnz(e,center_lat,sin_po); if (fabs(lat1 - lat2) > EPSLN)ns = log (ms1/ms2)/ log (ts1/ts2);elsens = con;f0 = ms1 / (ns * pow(ts1,ns));rh = r_major * f0 * pow(ts0,ns);/* Report parameters to the user-----------------------------*/ptitle("LAMBERT CONFORMAL CONIC");radius2(r_major, r_minor);stanparl(lat1,lat2);cenlonmer(center_lon);origin(c_lat);offsetp(false_easting,false_northing);return(OK);}lamccfor函数实现输入任意点经纬度值输出此投影下对应的点的大地坐标long lamccfor(lon, lat, x, y)double lon; /* (I) Longitude */ double lat; /* (I) Latitude */ double *x; /* (O) X projection coordinate */ double *y; /* (O) Y projection coordinate */{double con; /* temporary anglevariable */double rh1; /* height aboveellipsoid */double sinphi; /* sinvalue */double theta; /*angle */double ts; /* small valuet */con = fabs( fabs(lat) - HALF_PI);if (con > EPSLN){sinphi = sin(lat);ts = tsfnz(e,lat,sinphi);rh1 = r_major * f0 * pow(ts,ns);}else{con = lat * ns;if (con <= 0){p_error("Point can not be projected","lamcc-for"); return(44);}rh1 = 0;}theta = ns * adjust_lon(lon - center_lon);*x = rh1 * sin(theta) false_easting;*y = rh - rh1 * cos(theta) false_northing;return(OK);}lamccinv函数的作用与lamccfor函数相反,计算从大地坐标变换到对应的经纬度值long lamccinv(x , y, lon, lat)double x; /* (O) X projection coordinate */double y; /* (O) Y projection coordinate */double *lon; /* (I) Longitude */double *lat; /* (I) Latitude */{double rh1; /* height above ellipsoid */double con; /* sign variable */double ts; /* small t */double theta; /* angle */long flag; /* error flag */flag = 0;x -= false_easting;y = rh - y false_northing;if (ns > 0){rh1 = sqrt (x * x y * y);con = 1.0;}else{rh1 = -sqrt (x * x y * y);con = -1.0;}theta = 0.0;if (rh1 != 0)theta = atan2((con * x),(con * y)); if ((rh1 != 0) || (ns > 0.0)){con = 1.0/ns;ts = pow((rh1/(r_major * f0)),con); *lat = phi2z(e,ts,&flag);if (flag != 0)return(flag);}else*lat = -HALF_PI;*lon = adjust_lon(theta/ns center_lon); return(OK);}。
GPS数据解析 数据拆分 坐标转换 显示线路图源代码
view plaincopy to clipboardprint?1. GPS数据提取解析源码GPS source data extraction analysis, we can refer to learn from2.3.4. GPS数据解析5.6. 数据拆分 \坐标转换 \显示线路图\源代码7.8. 逐条读取gps数据然后进行拆分解析,坐标转换,绘制线路。
很好的示例多多交流学习。
9.10.11.12. 本程序是基于VC++ 建立的单文档工程。
13.14.15.16. 废话少说,直接上代码17.18.19.20. //获取子字符串个数21.22. i nt GetSubStrCount(CString str,char cFlag)23.24. {25.26. cFlag = ',';27.28. int i = 0;29.30. BOOL isHas = FALSE;31.32.33.34. for (int iStart = -1; -1 != (iStart = str.Find(cFlag,iStart+1)) ; i++)35.36. {37.38. isHas = TRUE;39.40. }41.42.43.44. if (!isHas)45.46. {47.48. return 0;49.50. }51.52. else53.54. {55.56. return i+1;57.58. }59.60. }61.62.63.64. //获取子字符串65.66. // i 序号 067.68. C String GetSubStr(CString str,int i,char cFlag)69.70. {71.72. cFlag = ',';73.74. int iStart = -1;75.76. int iEnd = 0;77.78. int j = 0;79.80. int iStrCount;81.82.83.84. iStrCount = GetSubStrCount(str,cFlag);85.86.87.88. if (i>iStrCount -1 || i<0)89.90. {91.92. str = "";93.94. return str;95.96. }97.98. else99.100. {101.102. //do nothing104. }105.106.107.108. if (i == iStrCount-1)109.110. {111.112. i = iStrCount;113.114.115.116. for (;j<i-1;j++)117.118. {119.120. iStart = str.Find(cFlag , iStart+1);121.122. }123.124.125.126. return str.Mid(iStart+1 , str.GetLength()-iStart-1); 127.128. }129.130. else131.132. {133.134. //do nothing135.136. }137.139.140. for (; j<i; j++)141.142. {143.144. iStart = str.Find(cFlag , iStart+1);145.146. }147.148.149.150. iEnd = str.Find(cFlag , iStart+1);151.152. return str.Mid(iStart+1 , iEnd-iStart-1);153.154. }155.156.157.158. //数据解析159.160. CString CGpsDataView::Analyzing(CString str)161.162. {163.164. CString subStr[20];165.166. char cFlag = ',';167.168. int j = GetSubStrCount(str,cFlag); //得到该行的子字符串个数169.170. CStdioFile wFile;171.172. wFile.Open("save.txt",CFile::modeCreate | CFile::modeWrite | CFil e::typeText);//将数据写入文件173.174.175.176. for (int i=0;i<j;i++)177.178. {179.180. subStr[i] = GetSubStr(str,i,cFlag); 181.182. }183.184.185.186. //GPGGA数据187.188. if (subStr[0] == "$GPGGA")189.190. {191.192. CoordCovert(subStr[2],subStr[4]);193.194. //提取时间195.196. subStr[1].Insert(2,':');197.198. subStr[1].Insert(5,':');199.200. subStr[1].Insert(0," UTC时间:");201.202.203.204. //提取纬度205.206. if (subStr[3] == 'N')207.208. {209.210. subStr[2].Insert(11,"分"); 211.212. subStr[2].Insert(2,"度"); 213.214. subStr[2].Insert(0," 北纬"); 215.216. }217.218. else if (subStr[3] == 'S')219.220. {221.222. subStr[2].Insert(11,"分"); 223.224. subStr[2].Insert(2,"度"); 225.226. subStr[2].Insert(0," 南纬"); 227.228. }229.230.231.232. //提取经度233.234. if (subStr[5] == 'E')235.236. {237.238. subStr[4].Insert(12,"分"); 239.240. subStr[4].Insert(3,"度");241.242. subStr[4].Insert(0," 东经"); 243.244. }245.246. else if (subStr[5] == 'W')247.248. {249.250. subStr[4].Insert(12,"分");251.252. subStr[4].Insert(3,"度");253.254. subStr[4].Insert(0," 西经"); 255.256. }257.258.259.260. //判断GPS状态261.262. CString GpsState;263.264.265.266. if (subStr[6] == '0')267.268. {269.270. GpsState = " GPS状态:无定位."; 271.272. }273.274. else if (subStr[6] == '1')275.276. {277.278. GpsState = " GPS状态:无差分校正定位."; 279.280. }281.282. else if (subStr[6] == '2')283.284. {285.286. GpsState = " GPS状态:差分校正定位."; 287.288. }289.290. else if (subStr[6] == '9')291.292. {293.294. GpsState = " GPS状态:用星历计算定位."; 295.296. }297.298.299.300. //提取卫星数301.302. subStr[7].Insert(0," 卫星数:");303.304.305.306. //提取平面位置精度因子307.308. subStr[8].Insert(0," 平面位置精度因子:"); 309.310.311.312. //天线海拔高度313.314. subStr[9].Insert(strlen(subStr[9]),subStr[10]); 315.316. subStr[9].Insert(0," 天线海拔高度:");317.318.319.320. //海平面分离度321.322. subStr[11].Insert(strlen(subStr[11]),subStr[12]); 323.324. subStr[11].Insert(0," 海平面分离度:");325.326.327.328. subStr[0] += subStr[1];329.330. subStr[0] += subStr[2];331.332. subStr[0] += subStr[4];333.334. subStr[0] += GpsState;335.336. subStr[0] += subStr[7];337.338. subStr[0] += subStr[8];339.340. subStr[0] += subStr[9];341.342. subStr[0] += subStr[11];343.344. //////////////////////////////////////MessageBox(subStr[0]); 345.346. wFile.WriteString(subStr[0]);//将数据写入文件347.348.349.350. }351.352.353.354. //GPZDA数据355.356. else if (subStr[0] == "$GPZDA")357.358. {359.360. //提取时间361.362. subStr[1].Insert(2,':');363.364. subStr[1].Insert(5,':');365.366. subStr[1].Insert(0," UTC时间:");367.368.369.370. //提取日期371.372. subStr[2].Insert(strlen(subStr[2]),"日"); 373.374. subStr[2].Insert(0,"月");375.376. subStr[2].Insert(0,subStr[3]);377.378. subStr[2].Insert(0,"年");379.380. subStr[2].Insert(0,subStr[4]);382. subStr[2].Insert(0,' ');383.384.385.386. //当地时域描述387.388. subStr[5].Insert(strlen(subStr[5]),"小时"); 389.390.391.392. if (strlen(subStr[6]) > 3)393.394. {395.396. subStr[6] = subStr[6].Left(2);397.398. }399.400. else401.402. {403.404. subStr[6] = '0';405.406. }407.408.409.410. subStr[6] += "分";411.412. subStr[6].Insert(0,subStr[5]);413.414. subStr[6].Insert(0," 当地时域:");415.417.418. subStr[0] += subStr[1];419.420. subStr[0] += subStr[2];421.422. subStr[0] += subStr[6];423.424. //////////////////////////////MessageBox(subStr[0]); 425.426. wFile.WriteString(subStr[0]);//将数据写入文件427.428. }429.430.431.432. //GPGSA数据433.434. else if (subStr[0] == "$GPGSA")435.436. {437.438. //卫星捕获模式,以及定位模式439.440. CString CatchLocation;441.442.443.444. if (subStr[1] == 'M')445.446. {447.448. if (subStr[2] == '1')449.450. {452. CatchLocation = " 手动捕获卫星,未定位!"; 453.454. }455.456. else if (subStr[2] == '2')457.458. {459.460. CatchLocation = " 手动捕获卫星,2D定位!"; 461.462. }463.464. else if (subStr[2] == '3')465.466. {467.468. CatchLocation = " 手动捕获卫星,3D定位!"; 469.470. }471.472. }473.474. else if (subStr[1] == 'A')475.476. {477.478. if (subStr[2] == '1')479.480. {481.482. CatchLocation =" 自动捕获卫星,未定位!"; 483.484. }485.486. else if (subStr[2] == '2')487.488. {489.490. CatchLocation =" 自动捕获卫星,2D定位!"; 491.492. }493.494. else if (subStr[2] == '3')495.496. {497.498. CatchLocation =" 自动捕获卫星,3D定位!"; 499.500. }501.502. }503.504.505.506. //各卫星定位结果507.508. subStr[3].Insert(0," 各卫星定位结果:");509.510. subStr[3] += ' ';511.512. subStr[4].Insert(0,subStr[3]);513.514. subStr[4] += ' ';515.516. subStr[5].Insert(0,subStr[4]);517.518. subStr[5] += ' ';519.520. subStr[6].Insert(0,subStr[5]);522. subStr[6] += ' ';523.524. subStr[7].Insert(0,subStr[6]); 525.526. subStr[7] += ' ';527.528. subStr[8].Insert(0,subStr[7]); 529.530. subStr[8] += ' ';531.532. subStr[9].Insert(0,subStr[8]); 533.534. subStr[9] += ' ';535.536. subStr[10].Insert(0,subStr[9]); 537.538. subStr[10] += ' ';539.540. subStr[11].Insert(0,subStr[10]); 541.542. subStr[11] += ' ';543.544. subStr[12].Insert(0,subStr[11]); 545.546. subStr[12] += ' ';547.548. subStr[13].Insert(0,subStr[12]); 549.550. subStr[13] += ' ';551.552. subStr[14].Insert(0,subStr[13]); 553.554. subStr[14] += ' ';555.557.558. //空间(三维)位置精度因子559.560. subStr[15].Insert(0," 空间(三维)位置精度因子:"); 561.562.563.564. //平面位置精度因子565.566. subStr[16].Insert(0," 平面位置精度因子:");567.568.569.570. //高度位置精度因子571.572. subStr[17] = subStr[17].Left(3);573.574. subStr[17].Insert(0," 高度位置精度因子:");575.576.577.578. subStr[0] += CatchLocation;579.580. subStr[0] += subStr[14];581.582. subStr[0] += subStr[15];583.584. subStr[0] += subStr[16];585.586. subStr[0] += subStr[17];587.588. /////////////////////////////MessageBox(subStr[0]);589.590. wFile.WriteString(subStr[0]);//将数据写入文件592. }593.594.595.596. //GPGSV数据597.598. else if (subStr[0] == "$GPGSV")599.600. {601.602. ///////////////////////////MessageBox(subStr[0]);603.604.605.606. //卫星编号、卫星仰角(0~90度)、卫星方位角(0~359度)、信噪比607.608. subStr[4].Insert(0,"卫星编号:");609.610. subStr[5].Insert(0," 仰角:");611.612. subStr[6].Insert(0," 方位角:");613.614. subStr[7].Insert(0," 信噪比:");615.616. subStr[4] += subStr[5];617.618. subStr[4] += subStr[6];619.620. subStr[4] += subStr[7];621.622. ///////////////////MessageBox(subStr[4]);623.624. subStr[8].Insert(0,"卫星编号:");626. subStr[9].Insert(0," 仰角:");627.628. subStr[10].Insert(0," 方位角:");629.630. subStr[11].Insert(0," 信噪比:");631.632. subStr[8] += subStr[9];633.634. subStr[8] += subStr[10];635.636. subStr[8] += subStr[11];637.638. ////////////////////////MessageBox(subStr[8]); 639.640. subStr[12].Insert(0,"卫星编号:"); 641.642. subStr[13].Insert(0," 仰角:");643.644. subStr[14].Insert(0," 方位角:");645.646. subStr[15].Insert(0," 信噪比:");647.648. subStr[12] += subStr[13];649.650. subStr[12] += subStr[14];651.652. subStr[12] += subStr[15];653.654. /////////////////////MessageBox(subStr[12]); 655.656. subStr[16].Insert(0,"卫星编号:"); 657.658. subStr[17].Insert(0," 仰角:");659.660. subStr[18].Insert(0," 方位角:");661.662.663.664. if (strlen(subStr[19]) > 3)665.666. {667.668. subStr[19] = subStr[19].Left(2);669.670. }671.672. else673.674. {675.676. subStr[19] = '0';677.678. }679.680.681.682. subStr[19].Insert(0," 信噪比:");683.684. subStr[16] += subStr[17];685.686. subStr[16] += subStr[18];687.688. subStr[16] += subStr[19];689.690. /////////////////////////////////MessageBox(subStr[16]); 691.692. wFile.WriteString(subStr[16]);//将数据写入文件693.694. }695.696. return str;697.698. }699.700.701.702.703.704. //读取文件数据并解析705.706. void CGpsDataView::OnFileRead()707.708. {709.710. // TODO: 在此添加命令处理程序代码711.712. CStdioFile myFile;713.714. CString oneLine;715.716. char cFlag = ',';717.718. CString subStr[20];719.720.721.722. //读取GPS数据文件723.724. if(!myFile.Open(("gps.txt"),CFile::modeRead | CFile::typeText)) 725.726. {727.728. AfxMessageBox(_T("打开文件错误!"));729.730. return;731.732. }733.734. else735.736. {737.738. /*do nothing*/739.740. }741.742.743.744. while (myFile.ReadString(oneLine))//读一行745.746. {747.748. //////////MessageBox(oneLine);749.750. int j = GetSubStrCount(oneLine,cFlag); //得到该行的子字符串个数751.752.753.754. //校验755.756. if(CheckNum(oneLine))757.758. {759.760. ////////////MessageBox(_T("数据校验...接收正确!...")); 761.762.763.764. for (int i=0;i<j;i++)765.766. {767.768. subStr[i] = GetSubStr(oneLine,i,cFlag); 769.770. //MessageBox(subStr[i]); 771.772. }773.774.775.776. Analyzing(oneLine); //解析777.778. }779.780. else781.782. {783.784. AfxMessageBox(_T("数据校验..接收错误!...")); 785.786. }787.788. }789.790.791.792. myFile.Close();793.794. }795.796.797.798. //******************************************************************************* ****************799.800. //坐标转换801.802.803.804. //度分秒--弧度805.806. double Dms2Rad(double Dms)807.808. {809.810. double Degree, Miniute;811.812. double Second;813.814. int Sign;815.816. double Rad;817.818.819.820. if(Dms >= 0)821.822. {823.824. Sign = 1;825.826. }827.828. else829.830. {831.832. Sign = -1;833.834. }835.836.837.838. Dms = fabs(Dms); //绝对值839.840. Degree = floor(Dms); // 取度 floor(2.800) = 2.0000841.842. Miniute = floor(fmod(Dms * 100.0, 100.0)); //fmod 计算余数843.844. Second = fmod(Dms * 10000.0, 100.0);845.846. Rad = Sign * (Degree + Miniute / 60.0 + Second / 3600.0) * PI / 180.0;847.848. return Rad;849.850. }851.852.853.854. double Rad2Dms(double Rad)855.856. {857.858. double Degree, Miniute;859.860. double Second;861.862. int Sign;863.864. double Dms;865.867.868. if(Rad >= 0)869.870. {871.872. Sign = 1;873.874. }875.876. else877.878. {879.880. Sign = -1;881.882. }883.884.885.886. Rad = fabs(Rad * 180.0 / PI);887.888. Degree = floor(Rad);889.890. Miniute = floor(fmod(Rad * 60.0, 60.0));891.892. Second = fmod(Rad * 3600.0, 60.0);893.894. Dms = Sign * (Degree + Miniute / 100.0 + Second / 10000.0); 895.896. return Dms;897.898. }899.900.902. //正算公式903.904. bool GpsPoint::BL2xy()905.906. {907.908. //大地测量学基础(吕志平乔书波北京:测绘出版社 2010.03)909.910.911.912. double X; //由赤道至纬度为B的子午线弧长(P106 5-41)913.914. double N; //椭球的卯酉圈曲率半径915.916. double t;917.918. double t2;919.920. double m;921.922. double m2;923.924. double ng2;925.926. double cosB;927.928. double sinB;929.930.931.932. X = A1 * B * 180.0 / PI + A2 * sin(2 * B)933.934. + A3 * sin(4 * B) + A4 * sin(6 * B);935.937.938. sinB = sin(B);939.940. cosB = cos(B);941.942. t = tan(B);943.944. t2 = t * t;945.946.947.948. N = a /sqrt(1 - e2 * sinB * sinB);949.950. m = cosB * (L - L0);951.952. m2 = m * m;953.954. ng2 = cosB * cosB * e2 / (1 - e2);955.956.957.958. //P156 (6-63公式)959.960. x = X + N * t *(( 0.5 + ( (5 - t2 + 9 * ng2 + 4 * ng2 * ng2) 961.962. / 24.0 + (61 - 58 * t2 + t2 * t2) * m2 / 720.0) * m2)* m2); 963.964.965.966. y = N * m * ( 1 + m2 * ( (1 - t2 + ng2) / 6.0 + m2 * ( 5 - 18 * t2 + t2 * t2967.968. + 14 * ng2 - 58 * ng2 * t2 ) / 120.0));969.971.972. //y += 500000;973.974.975.976. return true;977.978. }979.980.981.982. //反算公式983.984. bool GpsPoint::xy2BL()985.986. {987.988. double sinB;989.990. double cosB;991.992. double t;993.994. double t2;995.996. double N; //椭球的卯酉圈曲率半径997.998. double ng2;999.1000. double V;1001.1002. double yN;1003.1004. double preB0;1006. double B0;1007.1008. double eta;1009.1010. //y -= 500000;1011.1012. B0 = x / A1;1013.1014.1015.1016. do1017.1018. {1019.1020. preB0 = B0;1021.1022. B0 = B0 * PI / 180.0;1023.1024. B0 = (x - (A2 * sin(2 * B0) + A3 * sin(4 * B0) + A4 * sin(6 * B0 ))) / A1;1025.1026. eta = fabs(B0 - preB0);1027.1028. }while(eta > 0.000000001);1029.1030.1031.1032. B0 = B0 * PI / 180.0;1033.1034. B = Rad2Dms(B0);1035.1036. sinB = sin(B0);1037.1038. cosB = cos(B0);1040. t = tan(B0);1041.1042. t2 = t * t;1043.1044. N = a / sqrt(1 - e2 * sinB * sinB);1045.1046. ng2 = cosB * cosB * e2 / (1 - e2);1047.1048. V = sqrt(1 + ng2);1049.1050. yN = y / N;1051.1052.1053.1054. B = B0 - (yN * yN - (5 + 3 * t2 + ng2 - 9 * ng2 * t2) * yN * yN * yN * yN1055.1056. / 12.0 + (61 + 90 * t2 + 45 * t2 * t2) * yN * yN * yN * yN * y N * yN / 360.0)1057.1058. * V * V * t / 2;1059.1060.1061.1062. L = L0 + (yN - (1 + 2 * t2 + ng2) * yN * yN * yN / 6.0 + (5 + 28 * t2 + 241063.1064. * t2 * t2 + 6 * ng2 + 8 * ng2 * t2) * yN * yN * yN * yN * yN / 120.0) / cosB;1065.1066. return true;1067.1068. }1069.1071.1072. //设置中央子午线1073.1074. bool GpsPoint::SetL0(double dL0)1075.1076. {1077.1078. L0 = Dms2Rad(dL0);1079.1080. return true;1081.1082. }1083.1084.1085.1086. //将度分秒经纬度转换为弧度后再转换为平面坐标1087.1088. bool GpsPoint::SetBL(double dB, double dL) 1089.1090. {1091.1092. B = Dms2Rad(dB);1093.1094. L = Dms2Rad(dL);1095.1096. BL2xy();1097.1098. return true;1099.1100. }1101.1102.1103.1104. bool GpsPoint::GetBL(double *dB, double *dL)1106. {1107.1108. *dB = Rad2Dms(B);1109.1110. *dL = Rad2Dms(L);1111.1112. return true;1113.1114. }1115.1116.1117.1118. //将平面坐标转换为(弧度)经纬度1119.1120. bool GpsPoint::Setxy(double dx, double dy) 1121.1122. {1123.1124. x = dx;1125.1126. y = dy;1127.1128. xy2BL();1129.1130. return true;1131.1132. }1133.1134.1135.1136. bool GpsPoint::Getxy(double *dx, double *dy) 1137.1138. {1139.1140. *dx = x;1141.1142. *dy = y;1143.1144. return true;1145.1146. }1147.1148.1149.1150. GpsPoint_Krasovsky::GpsPoint_Krasovsky()1151.1152. {1153.1154. a = 6378245; //长半径1155.1156. f = 298.3; //扁率的倒数(扁率:(a-b)/a)1157.1158. e2 = 1 - ((f - 1) / f) * ((f - 1) / f); //第一偏心率的平方1159.1160. e12 = (f / (f - 1)) * (f / (f - 1)) - 1; //第二偏心率的平方1161.1162.1163.1164. // 克拉索夫斯基椭球1165.1166. A1 = 111134.8611;1167.1168. A2 = -16036.4803;1169.1170. A3 = 16.8281;1171.1172. A4 = -0.0220;1173.1174. }1175.1176.1177.1178. //*************坐标转换1179.1180. bool CGpsDataView::CoordCovert(CString latitude, CString longitude)1181.1182. {1183.1184. double bbb = atof(latitude);1185.1186. double lll = atof(longitude);1187.1188.1189.1190. //度分格式转换为度分秒格式1191.1192. bbb = Dm2Dms(bbb);1193.1194. lll = Dm2Dms(lll);1195.1196.1197.1198. double MyL0 ; //中央子午线1199.1200. double MyB = bbb ; //33 d 44 m 55.6666 s1201.1202. double MyL = lll ; //3度带,109 d 22 m 33.4444 s1203.1204.1205.1206. //计算当地中央子午线 ,3度带1207.1208. MyL0 = fabs(MyL);1209.1210. MyL0 = floor(MyL);1211.1212. MyL0 = 3 * floor(MyL0 / 3 );1213.1214.1215.1216. GpsPoint_Krasovsky MyPrj;1217.1218. MyPrj.SetL0(MyL0);1219.1220. MyPrj.SetBL(MyB, MyL);1221.1222. double OutMyX;1223.1224. double OutMyY;1225.1226. OutMyX = MyPrj.x; //正算结果:坐标x 1227.1228. OutMyY = MyPrj.y; //结果:坐标y 1229.1230.1231.1232. CString strTemp1;1233.1234. CString strTemp2;1235.1236. CString strTemp3;1237.1238. CString strTemp4;1239.1240.1241.1242. strTemp1.Format("%f",OutMyX);1244. strTemp2.Format("%f",OutMyY); 1245.1246. strTemp1.Insert(0,"x = "); 1247.1248. strTemp2.Insert(0," , y = "); 1249.1250. strTemp2.Insert(0,strTemp1); 1251.1252. strTemp2.Insert(0," 坐标转换: "); 1253.1254.1255.1256. strTemp3.Format("%f12",MyB); 1257.1258. strTemp4.Format("%f12",MyL); 1259.1260. strTemp3.Insert(0,"B = "); 1261.1262. strTemp4.Insert(0," L = "); 1263.1264. strTemp4.Insert(0,strTemp3); 1265.1266. strTemp2.Insert(0,strTemp4); 1267.1268. //MessageBox(strTemp2); 1269.1270.1271.1272. DrawPoint(MyPrj.x,MyPrj.y); 1273.1274.1275.1276. return true;1277.1279.1280.1281.1282. //================================== 1283.1284. //度分格式转换为度分秒格式1285.1286. double CGpsDataView::Dm2Dms(double Dm) 1287.1288. {1289.1290. double Dms;1291.1292. double temp;1293.1294. temp = Dm - floor(Dm);1295.1296. temp = (temp * 60) / 100;1297.1298. Dm = floor(Dm);1299.1300. Dm += temp;1301.1302. Dm = Dm /100;1303.1304. Dms = Dm;1305.1306. return Dms;1307.1308. }1309.1310.1311.1312.1314.1315.1316.1317.1318. //*************绘制线路显示出路线1319.1320. int count1=0;1321.1322. bool bFirst = true;1323.1324. double xTemp;1325.1326. double yTemp;1327.1328. void CGpsDataView::DrawPoint(double X, double Y) 1329.1330. {1331.1332. Sleep(100);1333.1334.1335.1336. //X = (X - floor(X))*100;1337.1338. //Y = (Y - floor(Y))*100;1339.1340.1341.1342. if (bFirst)1343.1344. {1345.1346. xTemp=X;1347.1348. yTemp=Y;1349.1350. bFirst=false;1351.1352. }1353.1354.1355.1356. CDC *pDC=GetDC();1357.1358. CPen pen(PS_SOLID,3,RGB(255,20,20));1359.1360. CPen *pOldPen;1361.1362. CBrush *pOldBrush;1363.1364. CBrush *pBrush=CBrush::FromHandle( (HBRUSH)GetStockObjec t(NULL_BRUSH) );1365.1366.1367.1368. pOldPen=pDC->SelectObject(&pen);1369.1370. pOldBrush=pDC->SelectObject(pBrush);1371.1372.1373.1374. int a=(int)(100.0-(X-xTemp)*800.0);1375.1376. int b=(int)(100.0+(Y-yTemp)*800.0);1377.1378.1379.1380. //绘制点显示路径1381.1382. pDC->Ellipse(a,b,a+5,b+5);1383.1384.1385.1386. //计数1387.1388. count1=count1+1;1389.1390. pDC->SelectObject( pOldBrush );1391.1392. pDC->SelectObject( pOldPen );1393.1394.1395.1396. CString str;1397.1398. str.Format("%.1f,%.1f,%d,%d,%d",X-xTemp,Y-yTemp,a,b,count1);1399.1400. pDC->TextOut(10,10,str);1401.1402. }。
坐标转换源代码--GPS定位程序(C--)
坐标转换源代码--GPS定位程序(C++)GPS数据处理中为了满足不同的需要,处理的数据要进行坐标转换,得到在不同坐标系统下的结果,下面是笛卡尔坐标系,大地坐标系,站心地平坐标系(线型和极坐标形式)之间的转换源代码:头文件:#ifndef _COORDCOVERT_H#define _COORDCOVERT_H#include "stdlib.h"//WGS-84椭球体参数const double a=6378137.0;//长半轴const double flattening=1/298.257223563;//扁率const double delta=0.0000001;typedef struct tagCRDCARTESIAN{double x;double y;double z;}CRDCARTESIAN;typedef CRDCARTESIAN *PCRDCARTESIAN;//笛卡尔坐标系typedef struct tagCRDGEODETIC{double longitude;double latitude;double height;}CRDGEODETIC;typedef CRDGEODETIC *PCRDGEODETIC;//大地坐标系typedef struct tagCRDTOPOCENTRIC{double northing;double easting;double upping;}CRDTOPOCENTRIC;typedef CRDTOPOCENTRIC *PCRDTOPOCENTRIC; //站心地平坐标系(线坐标形式)typedef struct tagCRDTOPOCENTRICPOLAR{ double range;double azimuth;double elevation;}CRDTOPOCENTRICPOLAR;typedef CRDTOPOCENTRICPOLAR *PCRDTOPOCENTRICPOLAR;//站心地平坐标系(极坐标形式)//由笛卡尔坐标转换为大地坐标void CartesianToGeodetic (PCRDGEODETIC pcg, PCRDCARTESIAN pcc, double dSemiMajorAxis, double dFlattening);//pcg:指向所转换出的大地坐标的指针;//pcc:指向待转换的笛卡尔坐标的指针;//dSemiMajorAxis:参考椭球的长半轴;//dFlattening:参考椭球的扁率。
大地坐标转换c代码
以下是一个大地坐标转换的C代码示例,它可以将经度、纬度和高程转换为笛卡尔坐标系中的x、y和z坐标。
```c#include <stdio.h>#include <math.h>#define RADIUS_EARTH 6371000.0 // 地球半径,单位为米void cartesian_coords(double longitude, double latitude, double height, double *x, double *y, double *z) {double r = RADIUS_EARTH + height; // 计算半径double sin_lat = sin(latitude * M_PI / 180.0);double cos_lat = cos(latitude * M_PI / 180.0);double sin_lon = sin(longitude * M_PI / 180.0);double cos_lon = cos(longitude * M_PI / 180.0);*x = r * cos_lon * cos_lat;*y = r * sin_lon * cos_lat;*z = r * sin_lat;}int main() {double longitude = 120.0; // 经度double latitude = 30.0; // 纬度double height = 0.0; // 高程,单位为米double x, y, z; // 笛卡尔坐标系中的x、y和z坐标cartesian_coords(longitude, latitude, height, &x, &y, &z);printf("经度:%lf\n", longitude);printf("纬度:%lf\n", latitude);printf("高程:%lf\n", height);printf("x坐标:%lf\n", x);printf("y坐标:%lf\n", y);printf("z坐标:%lf\n", z);return 0;}```该代码使用了地球半径和球面三角学公式将大地坐标转换为笛卡尔坐标系中的x、y和z坐标。
wince GPS C 编程完整精间版
#include "stdafx.h"#include <windows.h>#include <commctrl.h>#include <gpsapi.h>#pragma comment(lib,"gpsapi.lib")#define MAX_WAIT 5000#define MAX_AGE 3000#define GPS_CONTROLLER_EVENT_COUNT 3HANDLE s_hNewLocationData = CreateEvent(NULL, FALSE, FALSE, NULL); HANDLE s_hDeviceStateChange = CreateEvent(NULL, FALSE, FALSE, NULL); HANDLE s_hExitThread = CreateEvent(NULL, FALSE, FALSE, NULL);HANDLE s_hGPS_Device = GPSOpenDevice(s_hNewLocationData, s_hDeviceStateChange, NULL, NULL);FILE *logfd;WCHAR* GetTodayTime(WCHAR timeStr[255]){SYSTEMTIME time;GetLocalTime(&time);int nYear = time.wYear;int nMonth = time.wMonth;int nDay = time.wDay;int nHour = time.wHour;int nMinute = time.wMinute;int nSecond = time.wSecond;wsprintf(timeStr,L"%.4d-%.2d-%.2d%.2d:%.2d:%.2d",nYear,nMonth,nDay,nHour,nMinute,nSecond);return timeStr;}DWORD GPSThreadProc(__opt LPVOID lpParameter){//WCHAR *p_timeStr;WCHAR timeS[255];GPS_POSITION gps_Position = {0}; //放数据的DWORD dwRet = 0; //表状态的,具体状态干具体的事WCHAR msg[300];GPS_DEVICE gps_Device = {0}; //存放GPS设备信息,在GPSGetDeviceState前要赋值,如下HANDLE gpsHandles[GPS_CONTROLLER_EVENT_COUNT] = {s_hNewLocationData, s_hDeviceStateChange, s_hExitThread};gps_Position.dwSize = sizeof(gps_Position); //POSITION结构的第一个参数gps_Position.dwVersion = GPS_VERSION_1; //POSITION结构的第二个参数gps_Device.dwVersion = GPS_VERSION_1; //DEVICE结构的第二个参数gps_Device.dwSize = sizeof(gps_Device); //DEVICE结构的第一个参数GetTodayTime(timeS);fwprintf(log,L"%s: Start.\n",timeS);while (1) //循环获取{dwRet = WaitForMultipleObjects(GPS_CONTROLLER_EVENT_COUNT, gpsHandles, FALSE, 100);switch(dwRet){case WAIT_OBJECT_0: //有数据,获取并输出dwRet = GPSGetPosition(s_hGPS_Device, &gps_Position, MAX_AGE , 0);if(gps_Position.dblLongitude!=0){//p_timeStr=GetTodayTime(timeS);GetTodayTime(timeS);wsprintf(msg, L"%s: %.2d/%.2d,%f,%f\n",timeS,gps_Position.dwSatelliteCount ,gps_Position.dwSatellite sInView ,gps_Position.dblLongitude, gps_Position.dblLatitude);//MessageBox(NULL, msg, L"GpsState", 0);//WriteToLog(msg);fwprintf(logfd, L"%s",msg);}break;case WAIT_OBJECT_0 + 1: //设备状态变化,获取状态信息dwRet = GPSGetDeviceState(&gps_Device);ZeroMemory(&gps_Device, sizeof(gps_Device));gps_Device.dwVersion = GPS_VERSION_1;if (ERROR_SUCCESS == dwRet){ //状态获取成功,则获取定位信息dwRet = GPSGetPosition(s_hGPS_Device, &gps_Position, MAX_AGE , 0);if(gps_Position.dblLongitude!=0){//p_timeStr=GetTodayTime(timeS);GetTodayTime(timeS);wsprintf(msg, L"%s: %.2d/.2%d,%f,%f\n",timeS,gps_Position.dwSatelliteCount ,gps_Position.dwSatellite sInView,gps_Position.dblLongitude, gps_Position.dblLatitude);//MessageBox(NULL, msg, L"GpsState", 0);//WriteToLog(msg);fwprintf(logfd, L"%s",msg);}}break;case WAIT_OBJECT_0 + 2: //结束线程事件,关闭GPS设备GPSCloseDevice(s_hGPS_Device);return 1;default:break;}//获取间断时间Sleep(MAX_WAIT);}fclose(log);return 0;}int _tmain(int argc, _TCHAR* argv[]){logfd = fopen("\\GPS.txt","a+");if (logfd == NULL) return -1;DWORD m_dwThreadID; //创建线程HANDLE m_hThread = CreateThread(NULL, NULL, GPSThreadProc, NULL, NULL, &m_dwThreadID);GPSThreadProc(NULL);fclose(logfd);return 0;}。
GPS卫星位置的计算(C++程序计算)
GPS卫星位置的计算利用C++编写了一段能计算单一瞬时卫星坐标的程序,在运行程序之前,需做部分准备工作:(1)在F盘下建立一名为“单一卫星广播星历”的txt文件。
(2)从“广播星历.txt”文件中拷贝从卫星PRN号开始的8行数据到“单一卫星广播星历.txt”中(3)在编辑选项中,将全部的“D”替换为“E”。
下面为我所选取的一个广播星历:18 06 8 25 6 0 0.0-2.472363412380E-04-1.023*********E-12 0.000000000000E+001.410000000000E+02-1.721875000000E+01 4.502687555010E-09 1.413760604187E+00-7.990747690201E-07 7.598234573379E-03 1.118145883083E-05 5.153709835052E+034.536000000000E+05-1.303851604462E-08-1.095067942661E-01 1.527369022369E-079.571235745530E-01 1.640000000000E+02-2.656176299285E+00-8.0374********E-09-5.193073455211E-10 1.000000000000E+00 1.389000000000E+03 0.000000000000E+002.000000000000E+00 0.000000000000E+00-1.024*********E-08 1.410000000000E+024.464490000000E+05 4.000000000000E+00程序设计部分:#include<stdio.h>#include<math.h>int main(){int i = 0;double n[50], n0, nn, t, tk, Mk, Ek, Vk, Yk, Gu, Gr, Gi, uk, rk, ik, xk, yk, zk, X, Y, Z, Lk, UT, yy, mm, JD, gpsz;FILE *fp;fp = fopen("F:\\单一卫星广播星历.txt", "r");if (fp == NULL){printf ("文件打开失败!\n");return 0;}while (! feof (fp)){fscanf(fp, "%lf", &n[i]);i++;}n0 = (sqrt(3986005E+8))/pow(n[17], 3);nn = n0 + n[12];/*计算卫星运行的平均角速度*/UT = n[4] + (n[5] / 60) + (n[7] / 3600);/*民用日的时分秒化为实数时*/if (n[1] >= 80)/*广播星历中年只有后两位,化为4位,参考1980年1月6日0点*/ {if (n[1] == 80 && n[2] == 1 && n[3] < 6){n[1] = n[1] + 2000;}n[1] = n[1] + 1900;}else{n[1] = n[1] + 2000;}if (n[2] <= 2){yy = n[1] - 1;mm = n[2] + 12;}if (n[2] > 2){yy = n[1];mm = n[2];}JD = (int)(365.25 * yy) + (int)(30.6001 * (mm + 1)) + n[3] + (UT / 24) + 1720981.5;/*化为儒略日*/gpsz = (int)((JD - 2444244.5) / 7);/*计算GPS周*/t = (JD - 2444244.5 - 7 * gpsz) * 24 * 3600;/*得出GPS秒*/tk = t - n[18];/*tk1为中间值,用以判断tk与正负302400的关系,然后返回到tk上*/ while (tk > 302400 || tk < -302400){if (tk > 302400){tk = tk - 604800;}else{tk = tk + 604800;}}/*计算归化观测时间*/Mk = n[13] + nn * tk;/*观测时刻的卫星平近点角*/Ek = Mk;Ek = Mk + n[15] * sin(Ek);Ek = Mk + n[15] * sin(Ek);/*迭代两次计算观测时刻的偏近点角*/Vk = atan(sqrt(1 - n[15] * n[15]) * sin(Ek)) / (cos(Ek) - n[15]);/*真近点角*/Yk = Vk + n[24];/*升交距角*/Gu = n[14] * cos(2 * Yk) + n[16] * sin(2 * Yk);Gr = n[23] * cos(2 * Yk) + n[11] * sin(2 * Yk);Gi = n[19] * cos(2 * Yk) + n[21] * sin(2 * Yk);/*摄动改正项*/uk = Yk + Gu;rk = n[17] * n[17] * (1 - n[15] * cos(Ek)) + Gr;ik = n[22] + Gi + n[26] * tk;/*经摄动改正后的升交距角、卫星矢径、轨道倾角*/xk = rk * cos(uk);yk = rk * sin(uk);zk = 0;/*卫星在轨道坐标系的坐标*/Lk = n[20] + (n[25] - 7.29211515E-5) * tk - 7.29211515E-5 * n[18];/*观测时刻t的升交点经度*/X = xk * cos(Lk) - yk * cos(ik) * sin(Lk);Y = xk * sin(Lk) + yk * cos(ik) * cos(Lk);Z = yk * sin(ik);/*卫星在WGS-84坐标系的坐标*/printf("该卫星在WGS-84坐标系中的坐标为:\nX = %lf m\nY = %lf m\nZ = %lf m\n", X, Y, Z);fclose(fp);return 0;}计算结果:该卫星在WGS-84坐标系中的坐标为:X = 9223153.692525 mY = 24133486.931401 mZ = 6032585.919385 m。
坐标转换源代码
坐标转换源代码// Convert.cpp : implementation file//#include stdafx.h椣据畬敤尠坐标转换.h#include Convert.h#include Converting.h#include zbxtsz.h#include gybl.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif///////////////////////////////////////////////////////////////////// ////////// CConvert dialogCConvert::CConvert(CWnd* pParent /*=NULL*/): CDialog(CConvert::IDD, pParent){//{{AFX_DATA_INIT(CConvert)m_s21 = -1;m_s22 = -1;m_s23 = -1;m_s24 = -1;m_s25 = -1;m_s26 = -1;m_s27 = -1;m_New_Zyzwx = 0.0;m_Zyzwx = 0.0;//}}AFX_DATA_INIT}void CConvert::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CConvert)DDX_Control(pDX, IDC_NEW_Zyzwx, m_C_New_Zyzwx);DDX_Control(pDX, IDC_Zyzwx, m_C_Zyzwx);DDX_Control(pDX, IDC_ZBXT, m_Zbxt);DDX_Control(pDX, IDC_New_ZBXT, m_New_Zbxt);DDX_Control(pDX, IDC_Txfs1, m_Txfs1);DDX_Control(pDX, IDC_a21, m_c21);DDX_Control(pDX, IDC_a22, m_c22);DDX_Control(pDX, IDC_a23, m_c23);DDX_Control(pDX, IDC_a24, m_c24);DDX_Control(pDX, IDC_a25, m_c25);DDX_Control(pDX, IDC_a26, m_c26);DDX_Control(pDX, IDC_a27, m_c27);DDX_Radio(pDX, IDC_a21, m_s21);DDX_Radio(pDX, IDC_a22, m_s22);DDX_Radio(pDX, IDC_a23, m_s23);DDX_Radio(pDX, IDC_a24, m_s24);DDX_Radio(pDX, IDC_a25, m_s25);DDX_Radio(pDX, IDC_a26, m_s26);DDX_Radio(pDX, IDC_a27, m_s27);DDX_Text(pDX, IDC_NEW_Zyzwx, m_New_Zyzwx);DDX_Text(pDX, IDC_Zyzwx, m_Zyzwx);DDX_Control(pDX, IDC_Grid1, m_Grid1);DDX_Control(pDX, IDC_Grid2, m_Grid2);DDX_Control(pDX, IDC_Grid3, m_Grid3);DDX_Control(pDX, IDC_Grid4, m_Grid4);DDX_Control(pDX, IDC_Grid5, m_Grid5);DDX_Control(pDX, IDC_Grid6, m_Grid6);DDX_Control(pDX, IDC_Grid7, m_Grid7);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CConvert, CDialog)//{{AFX_MSG_MAP(CConvert)ON_BN_CLICKED(IDC_Dyzbxt, OnDyzbxt)ON_BN_CLICKED(IDC_Txfs1, OnTxfs1)ON_BN_CLICKED(IDC_Txfs2, OnTxfs2)ON_BN_CLICKED(IDC_Txfs3, OnTxfs3)ON_BN_CLICKED(IDC_Txfs4, OnTxfs4)ON_BN_CLICKED(IDC_a21, Ona21)ON_BN_CLICKED(IDC_a22, Ona22)ON_BN_CLICKED(IDC_a23, Ona23)ON_BN_CLICKED(IDC_a24, Ona24)ON_BN_CLICKED(IDC_a25, Ona25)ON_BN_CLICKED(IDC_a26, Ona26)ON_BN_CLICKED(IDC_a27, Ona27)ON_CBN_SELCHANGE(IDC_New_ZBXT, OnSelchangeNewZBXT)ON_CBN_SELCHANGE(IDC_ZBXT, OnSelchangeZbxt)ON_BN_CLICKED(ID_Insert, OnInsert)ON_BN_CLICKED(ID_Delete, OnDelete)ON_BN_CLICKED(ID_change, Onchange)ON_BN_CLICKED(ID_Input, OnInput)ON_BN_CLICKED(ID_Output, OnOutput)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////// ////////// CConvert message handlersvoid CConvert::OnDyzbxt(){CZbxtSz dlg;dlg.DoModal();int i,j;i=m_Zbxt.GetCount();for (j=0;j{ m_Zbxt.DeleteString(0);m_New_Zbxt.DeleteString(0);}GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){m_Zbxt.AddString(GyBl.Zbxt_work->XtName);m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);GyBl.Zbxt_work=GyBl.Zbxt_work->next;}SzzbxtName();}BOOL CConvert::OnInitDialog(){int i;k_mode=1;CDialog::OnInitDialog();CString sHeading;?慥楤杮?张?序号|点号 | 转换前 X 坐标 | 转换前); 换后标 Y 坐 | X | Y 坐标转换后坐标转m_Grid1.SetFormatString ( sHeading);|度纬 | 号点| 序号?慥楤杮?张?经度 | 转换后 X 坐标 | 转换后 Y 坐标 );m_Grid2.SetFormatString ( sHeading);?慥楤杮?张?序号| 点号 | X 坐标 | Y坐标 | 纬度 | 经度 ); m_Grid3.SetFormatString ( sHeading);?慥楤杮?张?序号| 点号 | B | L | H |X|Y|Z);m_Grid4.SetFormatString ( sHeading);?慥楤杮?张?序号| 点号 | X | Y | Z |B|L|H);m_Grid5.SetFormatString ( sHeading);for( i = 1; i < 8; i++ ){ m_Grid4.SetColWidth(i,1500);m_Grid5.SetColWidth(i,1500);}?慥楤杮?张?序号| 点号 | 转换前 X 坐标 | 转换前 Y 坐标 | 转换后 X 坐标 | 转换后 Y 坐标 );m_Grid6.SetFormatString ( sHeading);?慥楤杮?张?序号| 点号 | 转换前 X 坐标 | 转换前 Y 坐标 | 转换前 Z 坐标 | 转换后 X 坐标 | 转换后 Y 坐标 |转换前 Y 坐标 );m_Grid7.SetFormatString ( sHeading);m_Grid1.SetAllowUserResizing(1);m_Grid2.SetAllowUserResizing(1);m_Grid3.SetAllowUserResizing(1);m_Grid4.SetAllowUserResizing(1);m_Grid5.SetAllowUserResizing(1);m_Grid6.SetAllowUserResizing(1);m_Grid7.SetAllowUserResizing(1);m_Txfs1.SetCheck(1);Szzhfs();GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL)m_Zbxt.AddString(GyBl.Zbxt_work->XtName);m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);GyBl.Zbxt_work=GyBl.Zbxt_work->next;}SzzbxtName();ReadData();return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}void CConvert::OnTxfs1(){GyBl.WorkData.Mode=1;Szzhfs();}void CConvert::OnTxfs2(){GyBl.WorkData.Mode=2;Szzhfs();}void CConvert::OnTxfs3(){GyBl.WorkData.Mode=3;Szzhfs();}void CConvert::OnTxfs4(){GyBl.WorkData.Mode=4;Szzhfs();}void CConvert::Szzhfs(){m_c21.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2); m_c22.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2); m_c23.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2); m_c24.EnableWindow(GyBl.WorkData.Mode==3);m_c25.EnableWindow(GyBl.WorkData.Mode==3);m_c26.EnableWindow(GyBl.WorkData.Mode==4);m_c27.EnableWindow(GyBl.WorkData.Mode==4);Szzbxt();}CConvert::Szzbxt(){m_Zbxt.EnableWindow( ((GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2)& &(GyBl.WorkData.Ys[1]+GyBl.WorkData.Ys[2]+GyBl.WorkData.Ys[3]>=1)) || ( (GyBl.WorkData.Mode==3)&&(GyBl.WorkData.Ys[4]+GyBl.WorkData.Ys[5])));m_New_Zbxt.EnableWindow( (GyBl.WorkData.Mode==1||GyBl.WorkData.Mode== 2)&&(GyBl.WorkData.Ys[1]==1) );m_C_New_Zyzwx.EnableWindow( ((GyBl.WorkData.Mode==1||GyBl.WorkData.Mo de==2)&&(GyBl.WorkData.Ys[1]==1)) &&(!strcmp(GyBl.WorkData.New_Zbx?瑘潭敤尬系统保留)) );?晩?瑳捲灭???潗歲慄慴娮硢?瑘潭敤尬系统保留)==0){m_C_Zyzwx.EnableWindow((GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2) &&((GyBl.WorkData.Ys[1]==1||GyBl.WorkData.Ys[3]==1||GyBl.WorkData.Ys[2] ==1) ));}elsem_C_Zyzwx.EnableWindow(FALSE);m_c21.SetCheck(GyBl.WorkData.Ys[1]==1);m_c22.SetCheck(GyBl.WorkData.Ys[2]==1);m_c23.SetCheck(GyBl.WorkData.Ys[3]==1);m_c24.SetCheck(GyBl.WorkData.Ys[4]==1);m_c25.SetCheck(GyBl.WorkData.Ys[5]==1);m_c26.SetCheck(GyBl.WorkData.Ys[6]==1);m_c27.SetCheck(GyBl.WorkData.Ys[7]==1);Szinput();}void CConvert::Ona21(){GyBl.WorkData.Ys[1]=1;if (GyBl.WorkData.Ys[1]==1){GyBl.WorkData.Ys[2]=GyBl.WorkData.Ys[3]=0;}Szzbxt();}void CConvert::Ona22(){GyBl.WorkData.Ys[2]=1;if (GyBl.WorkData.Ys[2]==1){GyBl.WorkData.Ys[1]=GyBl.WorkData.Ys[3]=0;}Szzbxt();}void CConvert::Ona23(){GyBl.WorkData.Ys[3]=1;if (GyBl.WorkData.Ys[3]==1){GyBl.WorkData.Ys[1]=GyBl.WorkData.Ys[2]=0;}Szzbxt();}void CConvert::Ona24(){GyBl.WorkData.Ys[4]=1;if (GyBl.WorkData.Ys[4]==1) GyBl.WorkData.Ys[5]=0; Szzbxt();}void CConvert::Ona25(){GyBl.WorkData.Ys[5]=1;if (GyBl.WorkData.Ys[5]==1) GyBl.WorkData.Ys[4]=0;Szzbxt();}void CConvert::Ona26(){GyBl.WorkData.Ys[6]=1;if (GyBl.WorkData.Ys[6]==1) GyBl.WorkData.Ys[7]=0;Szzbxt();}void CConvert::Ona27(){GyBl.WorkData.Ys[7]=1;if (GyBl.WorkData.Ys[7]==1) GyBl.WorkData.Ys[6]=0;Szzbxt();}CConvert::SzzbxtName(){int i;i=0;GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){ i++;if (strcmp(GyBl.Zbxt_work->XtName,GyBl.WorkData.Zbxt.XtName)==0) break;GyBl.Zbxt_work=GyBl.Zbxt_work->next;}if (GyBl.Zbxt_work==NULL){i++;GyBl.NewZbxt();strcpy(GyBl.Zbxt_work->XtName,GyBl.WorkData.Zbxt.XtName);strcpy(GyBl.Zbxt_work->Xtmode,GyBl.WorkData.Zbxt.Xtmode);GyBl.Zbxt_work->Ra=GyBl.WorkData.Zbxt.Ra;GyBl.Zbxt_work->Bl=GyBl.WorkData.Zbxt.Bl;GyBl.Zbxt_work->Bl_num=GyBl.WorkData.Zbxt.Bl_num;GyBl.Zbxt_work->Zyzwx=GyBl.WorkData.Zbxt.Zyzwx;GyBl.Zbxt_work->Tyg=GyBl.WorkData.Zbxt.Tyg;GyBl.Zbxt_work->Xp=GyBl.WorkData.Zbxt.Xp;GyBl.Zbxt_work->Yp=GyBl.WorkData.Zbxt.Yp;m_Zbxt.AddString(GyBl.Zbxt_work->XtName);}m_Zbxt.SetCurSel(i-1);strcpy(GyBl.WorkData.Zbxt.Xtmode,GyBl.Zbxt_work->Xtmode);GyBl.WorkData.Zbxt.Ra=GyBl.Zbxt_work->Ra;GyBl.WorkData.Zbxt.Bl=GyBl.Zbxt_work->Bl;GyBl.WorkData.Zbxt.Bl_num=GyBl.Zbxt_work->Bl_num;GyBl.WorkData.Zbxt.Zyzwx=GyBl.Zbxt_work->Zyzwx;GyBl.WorkData.Zbxt.Tyg=GyBl.Zbxt_work->Tyg;GyBl.WorkData.Zbxt.Xp=GyBl.Zbxt_work->Xp;GyBl.WorkData.Zbxt.Yp=GyBl.Zbxt_work->Yp;m_Zyzwx=GyBl.WorkData.Zbxt.Zyzwx;i=0;GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){ i++;if(strcmp(GyBl.Zbxt_work->XtName,GyBl.WorkData.New_Zbxt.XtName)==0) break;GyBl.Zbxt_work=GyBl.Zbxt_work->next;}if (GyBl.Zbxt_work==NULL){i++;GyBl.NewZbxt();strcpy(GyBl.Zbxt_work->XtName,GyBl.WorkData.New_Zbxt.XtName); strcpy(GyBl.Zbxt_work->Xtmode,GyBl.WorkData.New_Zbxt.Xtmode); GyBl.Zbxt_work->Ra=GyBl.WorkData.New_Zbxt.Ra;GyBl.Zbxt_work->Bl=GyBl.WorkData.New_Zbxt.Bl;GyBl.Zbxt_work->Bl_num=GyBl.WorkData.New_Zbxt.Bl_num;GyBl.Zbxt_work->Zyzwx=GyBl.WorkData.New_Zbxt.Zyzwx;GyBl.Zbxt_work->Tyg=GyBl.WorkData.New_Zbxt.Tyg;GyBl.Zbxt_work->Xp=GyBl.WorkData.New_Zbxt.Xp;GyBl.Zbxt_work->Yp=GyBl.WorkData.New_Zbxt.Yp;m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);}m_New_Zbxt.SetCurSel(i-1);strcpy(GyBl.WorkData.New_Zbxt.Xtmode,GyBl.Zbxt_work->Xtmode); GyBl.WorkData.New_Zbxt.Ra=GyBl.Zbxt_work->Ra;GyBl.WorkData.New_Zbxt.Bl=GyBl.Zbxt_work->Bl;GyBl.WorkData.New_Zbxt.Bl_num=GyBl.Zbxt_work->Bl_num; GyBl.WorkData.New_Zbxt.Zyzwx=GyBl.Zbxt_work->Zyzwx; GyBl.WorkData.New_Zbxt.Tyg=GyBl.Zbxt_work->Tyg;GyBl.WorkData.New_Zbxt.Xp=GyBl.Zbxt_work->Xp;GyBl.WorkData.New_Zbxt.Yp=GyBl.Zbxt_work->Yp;m_New_Zyzwx=GyBl.WorkData.New_Zbxt.Zyzwx;CWnd::UpdateData(FALSE);Szzbxt();}void CConvert::OnSelchangeNewZBXT(){CString str;m_New_Zbxt.GetLBText(m_New_Zbxt.GetCurSel(),str);strcpy(GyBl.WorkData.New_Zbxt.XtName,str);SzzbxtName();}void CConvert::OnSelchangeZbxt(){CString str;m_Zbxt.GetLBText(m_Zbxt.GetCurSel(),str);strcpy(GyBl.WorkData.Zbxt.XtName,str);SzzbxtName();}CConvert::Szinput(){m_Grid1.ShowWindow(FALSE);m_Grid2.ShowWindow(FALSE);m_Grid3.ShowWindow(FALSE);m_Grid4.ShowWindow(FALSE);m_Grid5.ShowWindow(FALSE);m_Grid6.ShowWindow(FALSE);m_Grid7.ShowWindow(FALSE);if (GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2){m_Grid1.ShowWindow(GyBl.WorkData.Ys[1]==1);m_Grid2.ShowWindow(GyBl.WorkData.Ys[2]==1);m_Grid3.ShowWindow(GyBl.WorkData.Ys[3]==1);if(GyBl.WorkData.Ys[1]==1) k_mode=1;if(GyBl.WorkData.Ys[2]==1) k_mode=2;if(GyBl.WorkData.Ys[3]==1) k_mode=3;}if (GyBl.WorkData.Mode==3){m_Grid4.ShowWindow(GyBl.WorkData.Ys[4]==1);m_Grid5.ShowWindow(GyBl.WorkData.Ys[5]==1);if(GyBl.WorkData.Ys[4]==1) k_mode=4;if(GyBl.WorkData.Ys[5]==1) k_mode=5;}if (GyBl.WorkData.Mode==4){m_Grid6.ShowWindow(GyBl.WorkData.Ys[6]==1);m_Grid7.ShowWindow(GyBl.WorkData.Ys[7]==1);if(GyBl.WorkData.Ys[6]==1) k_mode=6;if(GyBl.WorkData.Ys[7]==1) k_mode=7;}}BEGIN_EVENTSINK_MAP(CConvert, CDialog)//{{AFX_EVENTSINK_MAP(CConvert)ON_EVENT(CConvert, IDC_Grid1, -600 /* Click */, OnClickGrid1, VTS_NONE) ON_EVENT(CConvert, IDC_Grid2, -600 /* Click */, OnClickGrid1, VTS_NONE) ON_EVENT(CConvert, IDC_Grid3, -600 /* Click */, OnClickGrid1, VTS_NONE) ON_EVENT(CConvert, IDC_Grid4, -600 /* Click */, OnClickGrid1, VTS_NONE) ON_EVENT(CConvert, IDC_Grid5, -600 /* Click */, OnClickGrid1, VTS_NONE) ON_EVENT(CConvert, IDC_Grid1, 71 /* EnterCell */, OnEnterCellGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid2, 71 /* EnterCell */, OnEnterCellGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid3, 71 /* EnterCell */, OnEnterCellGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid4, 71 /* EnterCell */, OnEnterCellGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid5, 71 /* EnterCell */, OnEnterCellGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid1, -603 /* KeyPress */, OnKeyPressGrid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid2, -603 /* KeyPress */, OnKeyPressGrid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid3, -603 /* KeyPress */, OnKeyPressGrid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid4, -603 /* KeyPress */, OnKeyPressGrid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid5, -603 /* KeyPress */, OnKeyPressGrid1, VTS_PI2)//}}AFX_EVENTSINK_MAPEND_EVENTSINK_MAP()void CConvert::OnClickGrid1(){TransferValue (FALSE);}void CConvert::OnEnterCellGrid1(){TransferValue (FALSE);}void CConvert::OnKeyPressGrid1(short FAR* KeyAscii){switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch ( (int) * KeyAscii) {case VK_BACK : //Backspace - delete the last character m_GridData .Delete (m_GridData .GetLength ()-1,1);break;case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':case '0':m_GridData = m_GridData + (TCHAR *) KeyAscii; break;case '.':if ((m_GridData.Find('.')==-1))m_GridData = m_GridData + (TCHAR *) KeyAscii;break;case '-':if (m_GridData==\)m_GridData = m_GridData + (TCHAR *) KeyAscii;break;default :if (m_Grid->GetCol()==1)m_GridData = m_GridData + (TCHAR*) KeyAscii;break;}TransferValue (TRUE);}BOOL CConvert::TransferValue(BOOL ToGrid){CString sText;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}if (ToGrid){ //Transfer value to Grid from Edit Boxswitch (k_mode){case 1:case 2:case 3:if (m_Grid->GetCol()<4) m_Grid->SetText(m_GridData); break;case 4:case 5:if (m_Grid->GetCol()<5) m_Grid->SetText(m_GridData); break;}} else {m_GridData = m_Grid->GetText ();m_Grid->SetBackColorSel(RGB(0,255,255));m_Grid->SetForeColor(RGB(255,0,0));}return TRUE;}void CConvert::OnInsert(){int i,j,k;CString str;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch (k_mode){case 1:case 2:case 3:i=m_Grid->GetRow();m_Grid->SetRows(m_Grid->GetRows()+1);for (j=m_Grid->GetRows()-1;j>i+1;j--){for (k=1;k<=5;k++){m_Grid->SetCol(k); m_Grid->SetRow(j-1);str=m_Grid->GetText();m_Grid->SetRow(j);m_Grid->SetText(str);}}str=\;m_Grid->SetCol(1);m_Grid->SetRow(i+1);m_Grid->SetText(str); m_Grid->SetCol(2);m_Grid->SetText(str); m_Grid->SetCol(3);m_Grid->SetText(str);m_Grid->SetCol(4);m_Grid->SetText(str);m_Grid->SetCol(5);m_Grid->SetText(str);break;case 4:case 5:i=m_Grid->GetRow();m_Grid->SetRows(m_Grid->GetRows()+1);for (j=m_Grid->GetRows()-1;j>i+1;j--){for (k=1;k<=7;k++){m_Grid->SetCol(k); m_Grid->SetRow(j-1);str=m_Grid->GetText();m_Grid->SetRow(j);m_Grid->SetText(str);}}str=\;m_Grid->SetCol(1);m_Grid->SetRow(i+1);m_Grid->SetText(str); m_Grid->SetCol(2);m_Grid->SetText(str); m_Grid->SetCol(3);m_Grid->SetText(str);m_Grid->SetCol(4);m_Grid->SetText(str);m_Grid->SetCol(5);m_Grid->SetText(str);m_Grid->SetCol(6);m_Grid->SetText(str);m_Grid->SetCol(7);m_Grid->SetText(str);break;}}void CConvert::OnDelete(){int i,j,k;CString str;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch (k_mode){case 1:case 2:case 3:i=m_Grid->GetRow();if (i==0) break;m_Grid->SetCol(1); m_Grid->SetRow(i); str=m_Grid->GetText();瑳?确认删除 +str;if (AfxMessageBox(str,MB_YESNO)==IDYES){for (j=i+1;jGetRows();j++){for (k=1;k<=5;k++){m_Grid->SetCol(k); m_Grid->SetRow(j);str=m_Grid->GetText();m_Grid->SetRow(j-1);m_Grid->SetText(str);}}m_Grid->SetRows(m_Grid->GetRows()-1);}break;case 4:case 5:i=m_Grid->GetRow();if (i==0) break;m_Grid->SetCol(1); m_Grid->SetRow(i); str=m_Grid->GetText();瑳?确认删除 +str;if (AfxMessageBox(str,MB_YESNO)==IDYES){for (j=i+1;jGetRows();j++){for (k=1;k<=7;k++){m_Grid->SetCol(k); m_Grid->SetRow(j); str=m_Grid->GetText();m_Grid->SetRow(j-1); m_Grid->SetText(str);}}m_Grid->SetRows(m_Grid->GetRows()-1);}break;}}void CConvert::OnOK(){// TODO: Add extra validation hereWriteData();CDialog::OnOK();}double CConvert::CallL0(double l,int mode){double d0,l0;d0=l*180.0/PI;// double xxx;l0=0;if (mode==0) GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;else GyBl.Zbxt_work= &GyBl.WorkData.New_Zbxt; //中央子午线计算椠?猨牴浣?祇求娮硢彴潷歲?瑘潭敤尬自定义坐标系统)==0){l0=GyBl.Zbxt_work->Zyzwx;l0=Deg(l0);// xxx=GyBl.Zbxt_work->Yp;}else{// xxx=500000.000;{// int tt;// 3度 6度计算CWnd::UpdateData(TRUE);if (mode==0)l0=m_Zyzwx;else l0=m_New_Zyzwx;}}l0=l0 *PI/180;//vSetSystem(WorkSpaceData.Zbxt.Ra,1/WorkSpaceData.Zbxt.Bl,0,l0,0,xxx,1 );return l0;}double CConvert::Deg(double a2){double d;double du,fen,miao;double nn;if (a2<0) { nn=-1;a2=-a2;} else nn=1;du=floor(a2); fen=floor((a2-du)*100);miao=((a2-du)*100-fen)*100;if (miao>=60) { fen++;miao=0;if (fen>=60) { fen=0;du++;}}d=du+fen/60+miao/3600;d=d*nn;return(d);}double CConvert::Dfm(double a2){double d;double du,fen,miao;double nn;if (a2<0) { nn=-1;a2=-a2;} else nn=1;du=floor(a2);fen=floor((a2-du)*60);miao=((a2-du)*60-fen)*60;if ((miao+0.00001)>=60) { fen++;miao=0;if (fen>=60) { fen=0;du++;}}d=du+fen/100+miao/10000;d=d*nn;return(d);}void CConvert::ReadData(){int i,j,k;char buf[100];double xx;m_Grid1.SetRows(1);m_Grid2.SetRows(1);m_Grid3.SetRows(1);m_Grid4.SetRows(1);m_Grid5.SetRows(1);m_Grid6.SetRows(1);m_Grid7.SetRows(1);FILE *in;in =fopen (data,+);if (in!=NULL){//m_Grid1fread(&j,sizeof(int),1,in);m_Grid1.SetRows(j);for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0) sprintf(buf,%.3f,xx); else strcpy(buf,\);}m_Grid1.SetCol(k); m_Grid1.SetText(buf);}}//m_Grid2fread(&j,sizeof(int),1,in);m_Grid2.SetRows(j);for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in); if (xx!=0){if (k<=3)sprintf(buf,%.8f,xx);elsesprintf(buf,%.3f,xx);}else strcpy(buf,\);}m_Grid2.SetCol(k); m_Grid2.SetText(buf); }}//m_Grid3fread(&j,sizeof(int),1,in);m_Grid3.SetRows(j);for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in); if (xx!=0){if (k<=3)sprintf(buf,%.3f,xx);elsesprintf(buf,%.8f,xx);}else strcpy(buf,\);}m_Grid3.SetCol(k); m_Grid3.SetText(buf); }}//m_Grid4fread(&j,sizeof(int),1,in);m_Grid4.SetRows(j);for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);for (k=1;k<=7;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in); if (xx!=0){if (k<=3)sprintf(buf,%.8f,xx);elsesprintf(buf,%.3f,xx);}else strcpy(buf,\);}m_Grid4.SetCol(k); m_Grid4.SetText(buf); }}//m_Grid5fread(&j,sizeof(int),1,in);m_Grid5.SetRows(j);for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);for (k=1;k<=7;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in); if (xx!=0){if ((k<=4)||(k==7))sprintf(buf,%.3f,xx);elsesprintf(buf,%.8f,xx);}else strcpy(buf,\);}m_Grid5.SetCol(k); m_Grid5.SetText(buf); }}fclose(in);}}void CConvert::WriteData(){int i,j,k;CString str;double xx;FILE *in;in =fopen (data,w+);//m_Grid1j=m_Grid1.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);for (k=1;k<=5;k++){m_Grid1.SetCol(k); str=m_Grid1.GetText(); xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in); }}//m_Grid2j=m_Grid2.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);for (k=1;k<=5;k++){m_Grid2.SetCol(k); str=m_Grid2.GetText(); xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in); }}//m_Grid3j=m_Grid3.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);for (k=1;k<=5;k++){m_Grid3.SetCol(k); str=m_Grid3.GetText(); xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in); }}//m_Grid4j=m_Grid4.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);for (k=1;k<=7;k++){m_Grid4.SetCol(k); str=m_Grid4.GetText(); xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in); }}//m_Grid5j=m_Grid5.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);for (k=1;k<=7;k++){m_Grid5.SetCol(k); str=m_Grid5.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}fclose(in);}void CConvert::Changejs(){CString str;double L0,L1;// double yyy,yyy1;double x1,y1,z1,x2,y2;double b1,l1,h1;//,b2,l2;int i,j;double MM;if (GyBl.WorkData.Mode==2)MM=0.9996;elseMM=1;switch (k_mode){case 1:L0=CallL0(0,0);j=m_Grid1.GetRows();for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);m_Grid1.SetCol(2); str=m_Grid1.GetText();x1=atof(str);m_Grid1.SetCol(3); str=m_Grid1.GetText();y1=atof(str);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L0, GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg);Converting.XYBL(x1,y1,&b1,&l1);L1=CallL0(l1,1);GyBl.Zbxt_work= &GyBl.WorkData.New_Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L1,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg); Converting.BLXY(b1,l1,&x2,&y2);m_Grid1.SetCol(4);str.Format(%.3f,x2);m_Grid1.SetText(str);m_Grid1.SetCol(5);str.Format(%.3f,y2);m_Grid1.SetText(str);}break;case 2:j=m_Grid2.GetRows();for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);m_Grid2.SetCol(2); str=m_Grid2.GetText();b1=Deg(atof(str));m_Grid2.SetCol(3); str=m_Grid2.GetText();l1=Deg(atof(str));L1=CallL0(l1,0);//转换为幅度GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L1,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg); Converting.BLXY(b1*PI/180,l1*PI/180,&x2,&y2);m_Grid2.SetCol(4); str.Format(%.3f,x2);m_Grid2.SetText(str);m_Grid2.SetCol(5);str.Format(%.3f,y2);m_Grid2.SetText(str);}break;case 3:L0=CallL0(0,0);j=m_Grid3.GetRows();for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);m_Grid3.SetCol(2); str=m_Grid3.GetText();x1=atof(str);m_Grid3.SetCol(3); str=m_Grid3.GetText();y1=atof(str);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg); Converting.XYBL(x1,y1,&b1,&l1);m_Grid3.SetCol(4);str.Format(%.8f,Dfm(b1*180/PI));m_Grid3.SetText(str);m_Grid3.SetCol(5);str.Format(%.8f,Dfm(l1*180/PI));m_Grid3.SetText(str);}break;case 4:L0=CallL0(0,0);j=m_Grid4.GetRows();for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);m_Grid4.SetCol(2); str=m_Grid4.GetText();b1=atof(str);m_Grid4.SetCol(3); str=m_Grid4.GetText();l1=atof(str);m_Grid4.SetCol(4); str=m_Grid4.GetText();h1=atof(str);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg); Converting.BLHXYZ(Deg(b1)*PI/180,Deg(l1)*PI/180,h1,&x1,&y1,&z1);m_Grid4.SetCol(5);str.Format(%.3f,x1);m_Grid4.SetText(str);m_Grid4.SetCol(6);str.Format(%.3f,y1);m_Grid4.SetText(str);m_Grid4.SetCol(7);str.Format(%.3f,z1);m_Grid4.SetText(str);}break;case 5:L0=CallL0(0,0);j=m_Grid5.GetRows();for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);m_Grid5.SetCol(2); str=m_Grid5.GetText();x1=atof(str);m_Grid5.SetCol(3); str=m_Grid5.GetText();y1=atof(str);m_Grid5.SetCol(4); str=m_Grid5.GetText();z1=atof(str);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work->Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg);Converting.XYZBLH(x1,y1,z1,&b1,&l1,&h1);m_Grid5.SetCol(5);str.Format(%.8f,Dfm(b1*180/PI));m_Grid5.SetText(str);m_Grid5.SetCol(6);str.Format(%.8f,Dfm(l1*180/PI));m_Grid5.SetText(str);m_Grid5.SetCol(7); str.Format(%.3f,h1);m_Grid5.SetText(str);}break;}}void CConvert::Onchange(){Changejs();}void CConvert::OnInput(){// int i,j,k;char buf[255],*po;// double xx;CFileDialog dlgFile(TRUE, *, NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, ????????导入数据 (*.*)|*.*||, NULL);if ( dlgFile.DoModal() != IDOK ) return ;// RET=main(dlgFile.GetPathName());FILE *in;switch (k_mode){case 1:break;case 2:m_Grid2.SetRows(1);in=fopen(dlgFile.GetPathName(),+);if (in==NULL) break;while (!feof(in)){if (fgets(buf,254,in)==NULL) break;if (strlen(buf)>10){。
大地坐标与空间坐标转换c++程序
}
void kd()
{
double x,y,z,b1,b2,b,l,h;
cout<<"输入空间直角坐标X,Y,Z"<<endl;
cin>>x;
cin>>y;
cin>>z;
b1=atan(z/sqrt(x*x+y*y));
b2=atan(((A*E*sin(b1))/sqrt(1-E*pow(sin(b1),2))+z)/(sqrt(x*x+y*y)));
}
void dk()
{
double B,L,H,x,y,z;
cout<<"输入大地坐标B,L,H"<<endl;
cin>>B;
cin>>L;
cin>>H;
B=B*PAI/180;
L=L*PAI/180;
x=(A/sqrt(1-E*pow(sin(B),2))+H)*cos(B)*cos(L);
y=(A/sqrt(1-E*pow(sin(B),2))+H)*cos(B)*sin(L);
}
大地坐标与空间坐标转换c程序
#include<iostream>
#include<cmath>
#include<iomanip>
#include <math.h>
#define E 0.006693422 //E=e2
#define PAI 3.141592654
using namespace std;
int main()
时间转换源代码--GPS定位程序
return morigin-long(morigin);
}
double mod(double a,int b)
{
return (a-b*long(a/b));
}
void CommonTimeToJulianDay(PCOMMONTIME pct, PJULIANDAY pjd)
{
int m;
int y;
}
void JulianDayToGPSTime (PJULIANDAY pjd, PGPSTIME pgt)
{
double JD;
JD=pjd->day+(pjd->tod.sn+pjd->tod.tos)/_DAY_IN_SECOND;
pgt->wn=int((JD-2444244.5)/7);
}
else {
y = pct->year;
m = pct->month;
}
pjd->day = (long)(365.25*y) + (long)(30.6001*(m+1))
+ pct->day + (long)(ut/24 + 1720981.5);
pjd->tod.sn = ((pct->hour+12)%_DAY_IN_HOUR)*_HOUR_IN_SECOND
void CommonTimeToJulianDay (PCOMMONTIME pct, PJULIANDAY pjd);
void JulianDayToCommonTime (PJULIANDAY pjd, PCOMMONTIME pct);
void JulianDayToGPSTime (PJULIANDAY pjd, PGPSTIME pgt);
GPS编码格式及C语言解码
GPS编码格式及C语⾔解码有关磁偏⾓和地图定位的问题:地图的⽅向:上北、下南、左西、右东是⼤多数地图的⽅向,但这可不是通⽤原则,如果地图上有⽅向标,可以通过⽅向标了解到这些。
地磁极是接近南极和北极的,但并不和南极、北极重合,⼀个约在北纬72°、 西经96°处;⼀个约在南纬70°、东经150°处。
磁北极距地理北极⼤约相差1500km。
现在磁北极的位置在加拿⼤北⽅,在⼀天中磁北极的位置也是不停的变动,它的轨迹⼤致为⼀椭圆形,磁北极平均每天向北以40m。
⽬前磁北极正在逐渐离开加拿⼤,⼤约于2005年进⼊俄罗斯境内。
东经25度地区,磁偏⾓在1-2度之间;北纬25度以上地区,磁偏⾓⼤于2度;若在西经低纬度地区,磁偏⾓是5-20度;西经45度以上,磁偏⾓为25-50度。
在我国,正常情况下,磁偏⾓最⼤可达6度,⼀般情况为2-3度。
在我国除部分磁⼒异常的地⽅外,⼀般磁偏⾓都是西偏。
磁偏⾓还是不断有规律变化的,地图上的磁偏⾓只是测图时的磁偏⾓(磁北⽐真北偏左,加上磁偏⾓;磁北⽐真北偏右,减去磁偏⾓;在我国⼀般是加上)。
使⽤地图本⾝所注的磁偏⾓要注意出版年限,地图太⽼误差较⼤。
GPS 0183协议GGA、GLL、GSA、GSV、RMC、VTG解释$GPGGA例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000*1F字段0:$GPGGA,语句ID,表明该语句为Global Positioning System Fix Data(GGA)GPS定位信息字段1:UTC 时间,hhmmss.sss,时分秒格式字段2:纬度ddmm.mmmm,度分格式(前导位数不⾜则补0)字段3:纬度N(北纬)或S(南纬)字段4:经度dddmm.mmmm,度分格式(前导位数不⾜则补0)字段5:经度E(东经)或W(西经)字段6:GPS状态,0=未定位,1=⾮差分定位,2=差分定位,3=⽆效PPS,6=正在估算字段7:正在使⽤的卫星数量(00 - 12)(前导位数不⾜则补0)字段8:HDOP⽔平精度因⼦(0.5 - 99.9)字段9:海拔⾼度(-9999.9 - 99999.9)字段10:地球椭球⾯相对⼤地⽔准⾯的⾼度字段11:差分时间(从最近⼀次接收到差分信号开始的秒数,如果不是差分定位将为空)字段12:差分站ID号0000 - 1023(前导位数不⾜则补0,如果不是差分定位将为空)字段13:校验值$GPGLL例:$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D字段0:$GPGLL,语句ID,表明该语句为Geographic Position(GLL)地理定位信息字段1:纬度ddmm.mmmm,度分格式(前导位数不⾜则补0)字段2:纬度N(北纬)或S(南纬)字段3:经度dddmm.mmmm,度分格式(前导位数不⾜则补0)字段4:经度E(东经)或W(西经)字段5:UTC时间,hhmmss.sss格式字段6:状态,A=定位,V=未定位字段7:校验值$GPGSA例:$GPGSA,A,3,01,20,19,13,,,,,,,,,40.4,24.4,32.2*0A字段0:$GPGSA,语句ID,表明该语句为GPS DOP and Active Satellites(GSA)当前卫星信息字段1:定位模式,A=⾃动⼿动2D/3D,M=⼿动2D/3D字段2:定位类型,1=未定位,2=2D定位,3=3D定位字段3:PRN码(伪随机噪声码),第1信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段4:PRN码(伪随机噪声码),第2信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段5:PRN码(伪随机噪声码),第3信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段6:PRN码(伪随机噪声码),第4信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段7:PRN码(伪随机噪声码),第5信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段8:PRN码(伪随机噪声码),第6信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段9:PRN码(伪随机噪声码),第7信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段10:PRN码(伪随机噪声码),第8信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段11:PRN码(伪随机噪声码),第9信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段12:PRN码(伪随机噪声码),第10信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段13:PRN码(伪随机噪声码),第11信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段14:PRN码(伪随机噪声码),第12信道正在使⽤的卫星PRN码编号(00)(前导位数不⾜则补0)字段15:PDOP综合位置精度因⼦(0.5 - 99.9) 字段16:HDOP⽔平精度因⼦(0.5 - 99.9)字段17:VDOP垂直精度因⼦(0.5 - 99.9)字段18:校验值$GPGSV例:$GPGSV,3,1,10,20,78,331,45,01,59,235,47,22,41,069,,13,32,252,45*70字段0:$GPGSV,语句ID,表明该语句为GPS Satellites in View(GSV)可见卫星信息字段1:本次GSV语句的总数⽬(1 - 3)字段2:本条GSV语句是本次GSV语句的第⼏条(1 - 3)字段3:当前可见卫星总数(00 - 12)(前导位数不⾜则补0)字段4:PRN 码(伪随机噪声码)(01 - 32)(前导位数不⾜则补0)字段5:卫星仰⾓(00 - 90)度(前导位数不⾜则补0)字段6:卫星⽅位⾓(00 - 359)度(前导位数不⾜则补0)字段7:信噪⽐(00-99)dbHz字段8:PRN 码(伪随机噪声码)(01 - 32)(前导位数不⾜则补0)字段9:卫星仰⾓(00 - 90)度(前导位数不⾜则补0)字段10:卫星⽅位⾓(00 - 359)度(前导位数不⾜则补0)字段11:信噪⽐(00-99)dbHz字段12:PRN 码(伪随机噪声码)(01 - 32)(前导位数不⾜则补0)字段13:卫星仰⾓(00 - 90)度(前导位数不⾜则补0)字段14:卫星⽅位⾓(00 - 359)度(前导位数不⾜则补0)字段15:信噪⽐(00-99)dbHz字段16:校验值$GPRMC例:$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50字段0:$GPRMC,语句ID,表明该语句为Recommended Minimum Specific GPS/TRANSIT Data(RMC)推荐最⼩定位信息 字段1:UTC时间,hhmmss.sss格式字段2:状态,A=定位,V=未定位字段3:纬度ddmm.mmmm,度分格式(前导位数不⾜则补0)字段4:纬度N(北纬)或S(南纬)字段5:经度dddmm.mmmm,度分格式(前导位数不⾜则补0)字段6:经度E(东经)或W(西经)字段7:速度,节,Knots字段8:⽅位⾓,度字段9:UTC⽇期,DDMMYY格式字段10:磁偏⾓,(000 - 180)度(前导位数不⾜则补0)字段11:磁偏⾓⽅向,E=东W=西字段16:校验值$GPVTG例:$GPVTG,89.68,T,,M,0.00,N,0.0,K*5F字段0:$GPVTG,语句ID,表明该语句为Track Made Good and Ground Speed(VTG)地⾯速度信息字段1:运动⾓度,000 - 359,(前导位数不⾜则补0)字段2:T=真北参照系字段3:运动⾓度,000 - 359,(前导位数不⾜则补0)字段4:M=磁北参照系字段5:⽔平运动速度(0.00)(前导位数不⾜则补0)字段6:N=节,Knots字段7:⽔平运动速度(0.00)(前导位数不⾜则补0)字段8:K=公⾥/时,km/h字段9:校验值GPS编码格式及C语⾔解码GPS接收机只要处于⼯作状态就会源源不断地把接收并计算出的GPS导航定位信息通过串⼝传送到计算机中。
GPS卫星位置计算(C语言)
#include <stdio.h>#include <math.h>#include <stdlib.h>#define bGM84 3.986005e14#define bOMEGAE84 7.2921151467e-5void main(){long double roota=0.515365263176E+04; //轨道长半轴的平方根(根号a)long double toe=0.720000000000E+04; //观测时刻toelong double m0=-0.290282040486E+00; //参考时刻toe的平近点角long double e=0.678421219345E-02; //轨道偏心率elong double delta_n=0.451411660250E-08;//卫星的摄动改正数△nlong double smallomega=-0.258419417299E+01;//近地点角距ωlong double cus=0.912137329578E-05;//纬度幅角正弦调和项改正的振幅(弧度)long double cuc=0.189989805222E-06;//纬度幅角余弦调和项改正的振幅(弧度)long double crs=0.406250000000E+01;//轨道半径的余弦调和项改正的振幅(m)long double crc=0.201875000000E+03;//轨道半径的正弦调和项改正的振幅(m)long double cis=0.949949026108E-07;//轨道倾角的余弦调和项改正的振幅(弧度)long double cic=0.130385160446E-07;//轨道倾角的正弦调和项改正的振幅(弧度)long double idot=-0.253939149013E-09;//轨道倾角变化率Ilong double i0=0.958512160302E+00; //轨道倾角(弧度)long double bigomega0=-0.137835982556E+01;//升交点赤经long double earthrate=bOMEGAE84; //地球自转的速率welong double bigomegadot=-0.856928551657e-08;long double t=0.720000000000E+04; //加入卫星钟差改正的归化时间long double A;long double n0=0,n,tk;long double mk,ek,tak,ik,omegak,phik,uk,rk;long double corr_u,corr_r,corr_i;long double xpk,ypk,xk,yk,zk;int i;printf("输入的数据:\n");printf("√a=%e \n",roota);printf("toe=%e \n",toe);printf("e=%e \n",e);printf("i0=%e \n",i0);printf("ω=%e \n",smallomega);printf("△n=%e \n",delta_n);printf("Ω0=%e \n",bigomega0);printf("I=%e \n",idot);printf("Cuc=%e \n",cuc);printf("Cus=%e \n",cus);printf("Crc=%e \n",crc);printf("Crs=%e \n",crs);printf("Cic=%e \n",cic);printf("Cis=%e \n",cis);printf("\n\n输出的结果为:\n",e);A=roota*roota;n0=sqrt(bGM84/(A*A*A));//平均角速度n0printf("n0=%.10lf \n",n0);tk=t-toe;//相对于参考时刻toe的归化时间tkprintf("tk=%.10lf \n",tk);n=n0+delta_n;//加摄动改正后的卫星平均角速度printf(" n=%.10lf \n",n);mk=m0+n*tk;//卫星平近点角printf("mk=%.10lf \n",mk);ek=mk;for(i=0;i<10;i++) ek=mk+e*sin(ek);//利用迭代法求偏近点角ekprintf("ek=%.10lf \n",ek);tak=atan2(sqrt(1.0-e*e)*sin(ek),cos(ek)-e);//真近点角Vk的计算printf("Vk=%.10lf \n",tak);phik=tak+smallomega;//升交距角φk的计算printf("φk=%.10lf \n",phik);corr_u=cus*sin(2.0*phik)+cuc*cos(2.0*phik);//升交距角u的摄动改正δu printf("δu=%.10lf \n",corr_u);corr_r=crs*sin(2.0*phik)+crc*cos(2.0*phik);//卫星矢量r的摄动改正δr printf("δr=%.10lf \n",corr_r);corr_i=cis*sin(2.0*phik)+cic*cos(2.0*phik);//轨道倾角i的摄动改正δi printf("δi=%.10lf \n",corr_i);uk=phik+corr_u;//升交距角uprintf("uk=%.10lf \n",uk);rk=A*(1.0-e*cos(ek))+corr_r;//卫星矢量rprintf("rk=%.10lf \n",rk);ik=i0+idot*tk+corr_i;//轨道倾角iprintf("ik=%.10lf \n",ik);xpk=rk*cos(uk);//卫星在轨道平面坐标系的坐标ypk=rk*sin(uk);printf("xpk=%.10lf \n",xpk);printf("ypk=%.10lf \n",ypk);omegak=bigomega0+(bigomegadot-earthrate)*tk-earthrate*toe;//升交点经度Ωk的计算printf("Ωk=%.10lf \n\n",omegak);xk=xpk*cos(omegak)-ypk*sin(omegak)*cos(ik);//地心固定坐标系的直角坐标yk=xpk*sin(omegak)+ypk*cos(omegak)*cos(ik);zk=ypk*sin(ik);printf("Xk=%.4lf \n",xk);printf("Yk=%.4lf \n",yk);printf("Zk=%.4lf \n",zk);}。
GPS坐标转换代码
{
*dB = Rad2Dms(B);
*dL = Rad2Dms(L);
return true;
}
bool PrjPoint::Setxy(double dx, double dy)
{
x = dx;
y = dy;
xy2BL();
return true;
}
bool PrjPoint::Getxy(double *dx, double *dy)
} bool PrjPoint::SetBL(double dB, double dL)
{
B = Dms2Rad(dB);
L = Dms2Rad(dL);
//B = dB;
//我靠,I wana say fuck
//L = dL; //del it !
BL2xy();
return true;
}
bool PrjPoint::GetBL(double *dB, double *dL)
Sign = 1; else
Sign = -1; Dms = fabs(Dms); Degree = floor(Dms); Miniute = floor(fmod(Dms * 100.0, 100.0)); Second = fmod(Dms * 10000.0, 100.0); Rad = Sign * (Degree + Miniute / 60.0 + Second / 3600.0) * PI / 1
PrjPoint_IUGG1975::PrjPoint_IUGG1975() //在类外定义构造成员函数,要加上类名和域限定 符 :: {
a = 6378140; f = 298.257; e2 = 1 - ((f - 1) / f) * ((f - 1) / f); e12 = (f / (f - 1)) * (f / (f - 1)) - 1; A1 = 111133.0047; //这几个 A 是什么意思? A2 = -16038.5282; A3 = 16.8326; A4 = -0.0220; } PrjPoint_IUGG1975::~PrjPoint_IUGG1975() //析构函数,释放构造函数占用的内存 { } /////////////////////////////////////////////////// // Definition of PrjPoint_Krasovsky /////////////////////////////////////////////////// PrjPoint_Krasovsky::PrjPoint_Krasovsky() { a = 6378245; f = 298.3; e2 = 1 - ((f - 1) / f) * ((f - 1) / f); e12 = (f / (f - 1)) * (f / (f - 1)) - 1; A1 = 111134.8611; A2 = -16036.4803; A3 = 16.8281; A4 = -0.0220; } PrjPoint_Krasovsky::~PrjPoint_Krasovsky()
坐标转换从经纬度坐标到大地坐标及源码
坐标转换从经纬度坐标到大地坐标及源码经纬度坐标(也称为地理坐标)是一种描述地球上位置的方式,是基于地球表面的经度(东西方向)和纬度(南北方向)的数值。
而大地坐标是指将地球看做一个椭球体,在地球表面上每个点都有一个与众不同的空间直角坐标系。
将经纬度坐标转换为大地坐标的过程称为坐标转换。
下面是一个实现经纬度坐标转换为大地坐标的示例代码(Python语言):```pythonimport mathdef geodetic_to_geocentric(latitude, longitude, altitude): #1.计算椭球体的参数#2.将经度和纬度转换为弧度latitude_rad = math.radians(latitude)longitude_rad = math.radians(longitude)#3.计算椭球体的参数eccentricity_squared = 2 * flattening - flattening ** 2normal_radius = semi_major_axis / math.sqrt(1 -eccentricity_squared * (math.sin(latitude_rad) ** 2)) #4.计算大地坐标系的坐标x = (normal_radius + altitude) * math.cos(latitude_rad) * math.cos(longitude_rad)y = (normal_radius + altitude) * math.cos(latitude_rad) * math.sin(longitude_rad)z = (normal_radius * (1 - eccentricity_squared) + altitude) * math.sin(latitude_rad)return x, y, zlatitude = 37.7749 # 纬度longitude = -122.4194 # 经度altitude = 0 # 海拔(以米为单位)x, y, z = geodetic_to_geocentric(latitude, longitude, altitude)print(f'X: {x} meters')print(f'Y: {y} meters')print(f'Z: {z} meters')```在上述代码中,`geodetic_to_geocentric` 函数接受经纬度坐标和海拔参数,并使用椭球体的参数计算大地坐标系的坐标。
GPS数据解析源代码
GPS数据解析源代码/* 结构体定义-- ------------------------------------------------------------------*/struct GPS_TIME{long int year;//长整型long int month;long int day;long int hour;long int minute;long int second;};struct GPS_GPGGA//GPS定位信息{char Command[7];//¥GPGGA,GPS定位信息char UTC[7];//hhmmss.ss世界时间,北京时间=UTC+8小时char WD[10];//ddmm.mmmm纬度char WDNS[2];//N/S纬度char JD[11];//dddmm.mmmm经度char JDWE[2];//W/E经度char POS_STATUS[2];//GPS质量指示,0:未定位,1:定位,2:差分定位char WXS[3];//0-12使用到的卫星数char HDOP[4];//0.5-99.9水平精确度char WH[6];//-9999.9-9999.9天线离海平面的高度char DA1[2];//天线高度单位mchar DH[5];//地理高度char DA2[4];//地理高度单位mchar SUM[3];//校验和};struct GPS_GPRMC//推荐最小数据量的GPS具体内容传输数据{unsigned char Command[7];//¥GPRMC,GPS最小定位信息unsigned char UTC[7];//世界时间unsigned char VA[2];//定位状态,A:未定位,V:定位unsigned char WD[9];//维度unsigned char WDNS[2];//维度,N:北纬,S:南纬unsigned char JD[10];//经度unsigned char JDWE[2];//经度,E:东经,W:西经unsigned char SPEED[6];//对地速度,单位为节,1节=1852m/hunsigned char XHQD[6];//方位角unsigned char DATE[9];//日期unsigned char SUM[3];//校验和};struct GPD_INF//从各个语句中解析出来的数据装入此结构体中{unsigned char VA;//定位状态,A:未定位,V:定位unsigned char WDNS;//double WD;//unsigned char JDWE;//double JD;//unsigned char POS_STATUS;//GPS质量指示,0:未定位,1:定位,2:差分定位unsigned char WXS;//使用到的卫星数float HDOP;//水平方向的定位精度劣化程序系数float SPEED;//对地速度,单位为节,1节=1852m/hfloat XHQD;//方位角struct GPS_TIME TIME;//时间日期};/************************************************************** ****************** 函数名称 : GPS_S()* 函数功能 : 对数据帧进行子串化* 输入 : char *s* 输出 : None* 返回值 : 1* 备注 : 将数据中的“,”替换成'\0' ,将整个字符串分割为若干个字符串。
NEMA格式 GPS数据提取解析 坐标转换等 源码
GPS数据提取解析源码GPS source data extraction analysis, we can refer to learn fromGPS数据解析数据拆分\坐标转换\显示线路图\源代码逐条读取gps数据然后进行拆分解析,坐标转换,绘制线路。
很好的示例多多交流学习。
本程序是基于VC++ 建立的单文档工程。
废话少说,直接上代码//获取子字符串个数int GetSubStrCount(CString str,char cFlag){cFlag = ',';int i = 0;BOOL isHas = FALSE;for (int iStart = -1; -1 != (iStart = str.Find(cFlag,iStart+1)) ; i++){isHas = TRUE;}if (!isHas){return 0;}else{return i+1;}}//获取子字符串// i 序号0CString GetSubStr(CString str,int i,char cFlag){cFlag = ',';int iStart = -1;int iEnd = 0;int j = 0;int iStrCount;iStrCount = GetSubStrCount(str,cFlag);if (i>iStrCount -1 || i<0){str = "";return str;}else{//do nothing}if (i == iStrCount-1){i = iStrCount;for (;j<i-1;j++){iStart = str.Find(cFlag , iStart+1);}return str.Mid(iStart+1 , str.GetLength()-iStart-1);}else{//do nothing}for (; j<i; j++){iStart = str.Find(cFlag , iStart+1);}iEnd = str.Find(cFlag , iStart+1);return str.Mid(iStart+1 , iEnd-iStart-1);}//数据解析CString CGpsDataView::Analyzing(CString str){CString subStr[20];char cFlag = ',';int j = GetSubStrCount(str,cFlag); //得到该行的子字符串个数CStdioFile wFile;wFile.Open("save.txt",CFile::modeCreate | CFile::modeWrite | CFile::typeText);//将数据写入文件for (int i=0;i<j;i++){subStr[i] = GetSubStr(str,i,cFlag); }//GPGGA数据if (subStr[0] == "$GPGGA"){CoordCovert(subStr[2],subStr[4]);//提取时间subStr[1].Insert(2,':');subStr[1].Insert(5,':');subStr[1].Insert(0," UTC时间:");//提取纬度if (subStr[3] == 'N'){subStr[2].Insert(11,"分");subStr[2].Insert(2,"度");subStr[2].Insert(0," 北纬");}else if (subStr[3] == 'S'){subStr[2].Insert(11,"分");subStr[2].Insert(2,"度");subStr[2].Insert(0," 南纬");}//提取经度if (subStr[5] == 'E'){subStr[4].Insert(12,"分");subStr[4].Insert(3,"度");subStr[4].Insert(0," 东经");}else if (subStr[5] == 'W'){subStr[4].Insert(12,"分");subStr[4].Insert(3,"度");subStr[4].Insert(0," 西经");}//判断GPS状态CString GpsState;if (subStr[6] == '0'){GpsState = " GPS状态:无定位.";}else if (subStr[6] == '1'){GpsState = " GPS状态:无差分校正定位.";}else if (subStr[6] == '2'){GpsState = " GPS状态:差分校正定位.";}else if (subStr[6] == '9'){GpsState = " GPS状态:用星历计算定位.";}//提取卫星数subStr[7].Insert(0," 卫星数:");//提取平面位置精度因子subStr[8].Insert(0," 平面位置精度因子:");//天线海拔高度subStr[9].Insert(strlen(subStr[9]),subStr[10]);subStr[9].Insert(0," 天线海拔高度:");//海平面分离度subStr[11].Insert(strlen(subStr[11]),subStr[12]);subStr[11].Insert(0," 海平面分离度:");subStr[0] += subStr[1];subStr[0] += subStr[2];subStr[0] += subStr[4];subStr[0] += GpsState;subStr[0] += subStr[7];subStr[0] += subStr[8];subStr[0] += subStr[9];subStr[0] += subStr[11];//////////////////////////////////////MessageBox(subStr[0]);wFile.WriteString(subStr[0]);//将数据写入文件}//GPZDA数据else if (subStr[0] == "$GPZDA"){//提取时间subStr[1].Insert(2,':');subStr[1].Insert(5,':');subStr[1].Insert(0," UTC时间:");//提取日期subStr[2].Insert(strlen(subStr[2]),"日");subStr[2].Insert(0,"月");subStr[2].Insert(0,subStr[3]);subStr[2].Insert(0,"年");subStr[2].Insert(0,subStr[4]);subStr[2].Insert(0,' ');//当地时域描述subStr[5].Insert(strlen(subStr[5]),"小时");if (strlen(subStr[6]) > 3){subStr[6] = subStr[6].Left(2);}else{subStr[6] = '0';}subStr[6] += "分";subStr[6].Insert(0,subStr[5]);subStr[6].Insert(0," 当地时域:");subStr[0] += subStr[1];subStr[0] += subStr[2];subStr[0] += subStr[6];//////////////////////////////MessageBox(subStr[0]);wFile.WriteString(subStr[0]);//将数据写入文件}//GPGSA数据else if (subStr[0] == "$GPGSA"){//卫星捕获模式,以及定位模式CString CatchLocation;if (subStr[1] == 'M'){if (subStr[2] == '1'){CatchLocation = " 手动捕获卫星,未定位!";}else if (subStr[2] == '2'){CatchLocation = " 手动捕获卫星,2D定位!";}else if (subStr[2] == '3'){CatchLocation = " 手动捕获卫星,3D定位!";}}else if (subStr[1] == 'A'){if (subStr[2] == '1'){CatchLocation =" 自动捕获卫星,未定位!";}else if (subStr[2] == '2'){CatchLocation =" 自动捕获卫星,2D定位!";}else if (subStr[2] == '3'){CatchLocation =" 自动捕获卫星,3D定位!";}}//各卫星定位结果subStr[3].Insert(0," 各卫星定位结果:");subStr[3] += ' ';subStr[4].Insert(0,subStr[3]);subStr[4] += ' ';subStr[5].Insert(0,subStr[4]);subStr[5] += ' ';subStr[6].Insert(0,subStr[5]);subStr[6] += ' ';subStr[7].Insert(0,subStr[6]);subStr[7] += ' ';subStr[8].Insert(0,subStr[7]);subStr[8] += ' ';subStr[9].Insert(0,subStr[8]);subStr[9] += ' ';subStr[10].Insert(0,subStr[9]);subStr[10] += ' ';subStr[11].Insert(0,subStr[10]);subStr[11] += ' ';subStr[12].Insert(0,subStr[11]);subStr[12] += ' ';subStr[13].Insert(0,subStr[12]);subStr[13] += ' ';subStr[14].Insert(0,subStr[13]);subStr[14] += ' ';//空间(三维)位置精度因子subStr[15].Insert(0," 空间(三维)位置精度因子:");//平面位置精度因子subStr[16].Insert(0," 平面位置精度因子:");//高度位置精度因子subStr[17] = subStr[17].Left(3);subStr[17].Insert(0," 高度位置精度因子:");subStr[0] += CatchLocation;subStr[0] += subStr[14];subStr[0] += subStr[15];subStr[0] += subStr[16];subStr[0] += subStr[17];/////////////////////////////MessageBox(subStr[0]);wFile.WriteString(subStr[0]);//将数据写入文件}//GPGSV数据else if (subStr[0] == "$GPGSV"){///////////////////////////MessageBox(subStr[0]);//卫星编号、卫星仰角(0~90度)、卫星方位角(0~359度)、信噪比subStr[4].Insert(0,"卫星编号:");subStr[5].Insert(0," 仰角:");subStr[6].Insert(0," 方位角:");subStr[7].Insert(0," 信噪比:");subStr[4] += subStr[5];subStr[4] += subStr[6];subStr[4] += subStr[7];///////////////////MessageBox(subStr[4]);subStr[8].Insert(0,"卫星编号:");subStr[9].Insert(0," 仰角:");subStr[10].Insert(0," 方位角:");subStr[11].Insert(0," 信噪比:");subStr[8] += subStr[9];subStr[8] += subStr[10];subStr[8] += subStr[11];////////////////////////MessageBox(subStr[8]);subStr[12].Insert(0,"卫星编号:");subStr[13].Insert(0," 仰角:");subStr[14].Insert(0," 方位角:");subStr[15].Insert(0," 信噪比:");subStr[12] += subStr[13];subStr[12] += subStr[14];subStr[12] += subStr[15];/////////////////////MessageBox(subStr[12]);subStr[16].Insert(0,"卫星编号:");subStr[17].Insert(0," 仰角:");subStr[18].Insert(0," 方位角:");if (strlen(subStr[19]) > 3){subStr[19] = subStr[19].Left(2);}else{subStr[19] = '0';}subStr[19].Insert(0," 信噪比:");subStr[16] += subStr[17];subStr[16] += subStr[18];subStr[16] += subStr[19];/////////////////////////////////MessageBox(subStr[16]);wFile.WriteString(subStr[16]);//将数据写入文件}return str;}//读取文件数据并解析void CGpsDataView::OnFileRead(){// TODO: 在此添加命令处理程序代码CStdioFile myFile;CString oneLine;char cFlag = ',';CString subStr[20];//读取GPS数据文件if(!myFile.Open(("gps.txt"),CFile::modeRead | CFile::typeText)){AfxMessageBox(_T("打开文件错误!"));return;}else{/*do nothing*/}while (myFile.ReadString(oneLine))//读一行{//////////MessageBox(oneLine);int j = GetSubStrCount(oneLine,cFlag); //得到该行的子字符串个数//校验if(CheckNum(oneLine)){////////////MessageBox(_T("数据校验...接收正确!..."));for (int i=0;i<j;i++){subStr[i] = GetSubStr(oneLine,i,cFlag);//MessageBox(subStr[i]);}Analyzing(oneLine); //解析}else{AfxMessageBox(_T("数据校验..接收错误!..."));}}myFile.Close();}//*********************************************************************************** ************//坐标转换//度分秒--弧度double Dms2Rad(double Dms){double Degree, Miniute;double Second;int Sign;double Rad;if(Dms >= 0){Sign = 1;}else{Sign = -1;}Dms = fabs(Dms); //绝对值Degree = floor(Dms); // 取度floor(2.800)= 2.0000Miniute = floor(fmod(Dms * 100.0, 100.0)); //fmod 计算余数Second = fmod(Dms * 10000.0, 100.0);Rad = Sign * (Degree + Miniute / 60.0 + Second / 3600.0) * PI / 180.0;return Rad;}double Rad2Dms(double Rad){double Degree, Miniute;double Second;int Sign;double Dms;if(Rad >= 0){Sign = 1;}else{Sign = -1;}Rad = fabs(Rad * 180.0 / PI);Degree = floor(Rad);Miniute = floor(fmod(Rad * 60.0, 60.0));Second = fmod(Rad * 3600.0, 60.0);Dms = Sign * (Degree + Miniute / 100.0 + Second / 10000.0);return Dms;}//正算公式bool GpsPoint::BL2xy(){//大地测量学基础(吕志平乔书波北京:测绘出版社2010.03)double X; //由赤道至纬度为B的子午线弧长(P106 5-41)double N; //椭球的卯酉圈曲率半径double t;double t2;double m;double m2;double ng2;double cosB;double sinB;X = A1 * B * 180.0 / PI + A2 * sin(2 * B)+ A3 * sin(4 * B) + A4 * sin(6 * B);sinB = sin(B);cosB = cos(B);t = tan(B);t2 = t * t;N = a /sqrt(1 - e2 * sinB * sinB);m = cosB * (L - L0);m2 = m * m;ng2 = cosB * cosB * e2 / (1 - e2);//P156 (6-63公式)x = X + N * t *(( 0.5 + ( (5 - t2 + 9 * ng2 + 4 * ng2 * ng2)/ 24.0 + (61 - 58 * t2 + t2 * t2) * m2 / 720.0) * m2)* m2);y = N * m * ( 1 + m2 * ( (1 - t2 + ng2) / 6.0 + m2 * ( 5 - 18 * t2 + t2 * t2 + 14 * ng2 - 58 * ng2 * t2 ) / 120.0));//y += 500000;return true;}//反算公式bool GpsPoint::xy2BL(){double sinB;double cosB;double t;double t2;double N; //椭球的卯酉圈曲率半径double ng2;double V;double yN;double preB0;double B0;double eta;//y -= 500000;B0 = x / A1;do{preB0 = B0;B0 = B0 * PI / 180.0;B0 = (x - (A2 * sin(2 * B0) + A3 * sin(4 * B0) + A4 * sin(6 * B0))) / A1;eta = fabs(B0 - preB0);}while(eta > 0.000000001);B0 = B0 * PI / 180.0;B = Rad2Dms(B0);sinB = sin(B0);cosB = cos(B0);t = tan(B0);t2 = t * t;N = a / sqrt(1 - e2 * sinB * sinB);ng2 = cosB * cosB * e2 / (1 - e2);V = sqrt(1 + ng2);yN = y / N;B = B0 - (yN * yN - (5 + 3 * t2 + ng2 - 9 * ng2 * t2) * yN * yN * yN * yN/ 12.0 + (61 + 90 * t2 + 45 * t2 * t2) * yN * yN * yN * yN * yN * yN / 360.0)* V * V * t / 2;L = L0 + (yN - (1 + 2 * t2 + ng2) * yN * yN * yN / 6.0 + (5 + 28 * t2 + 24* t2 * t2 + 6 * ng2 + 8 * ng2 * t2) * yN * yN * yN * yN * yN / 120.0) / cosB;return true;}//设置中央子午线bool GpsPoint::SetL0(double dL0){L0 = Dms2Rad(dL0);return true;}//将度分秒经纬度转换为弧度后再转换为平面坐标bool GpsPoint::SetBL(double dB, double dL){B = Dms2Rad(dB);L = Dms2Rad(dL);BL2xy();return true;}bool GpsPoint::GetBL(double *dB, double *dL){*dB = Rad2Dms(B);*dL = Rad2Dms(L);return true;}//将平面坐标转换为(弧度)经纬度bool GpsPoint::Setxy(double dx, double dy){x = dx;y = dy;xy2BL();return true;}bool GpsPoint::Getxy(double *dx, double *dy){*dx = x;*dy = y;return true;}GpsPoint_Krasovsky::GpsPoint_Krasovsky(){a = 6378245; //长半径f = 298.3; //扁率的倒数(扁率:(a-b)/a)e2 = 1 - ((f - 1) / f) * ((f - 1) / f); //第一偏心率的平方e12 = (f / (f - 1)) * (f / (f - 1)) - 1; //第二偏心率的平方// 克拉索夫斯基椭球A1 = 111134.8611;A2 = -16036.4803;A3 = 16.8281;A4 = -0.0220;}//*************坐标转换bool CGpsDataView::CoordCovert(CString latitude, CString longitude){double bbb = atof(latitude);double lll = atof(longitude);//度分格式转换为度分秒格式bbb = Dm2Dms(bbb);lll = Dm2Dms(lll);double MyL0 ; //中央子午线double MyB = bbb ; //33 d 44 m 55.6666 sdouble MyL = lll ; //3度带,109 d 22 m 33.4444 s//计算当地中央子午线,3度带MyL0 = fabs(MyL);MyL0 = floor(MyL);MyL0 = 3 * floor(MyL0 / 3 );GpsPoint_Krasovsky MyPrj;MyPrj.SetL0(MyL0);MyPrj.SetBL(MyB, MyL);double OutMyX;double OutMyY;OutMyX = MyPrj.x; //正算结果:坐标xOutMyY = MyPrj.y; //结果:坐标yCString strTemp1;CString strTemp2;CString strTemp3;CString strTemp4;strTemp1.Format("%f",OutMyX);strTemp2.Format("%f",OutMyY);strTemp1.Insert(0,"x = ");strTemp2.Insert(0," , y = ");strTemp2.Insert(0,strTemp1);strTemp2.Insert(0," 坐标转换: ");strTemp3.Format("%f12",MyB);strTemp4.Format("%f12",MyL);strTemp3.Insert(0,"B = ");strTemp4.Insert(0," L = ");strTemp4.Insert(0,strTemp3);strTemp2.Insert(0,strTemp4);//MessageBox(strTemp2);DrawPoint(MyPrj.x,MyPrj.y);return true;}//================================== //度分格式转换为度分秒格式double CGpsDataView::Dm2Dms(double Dm){double Dms;double temp;temp = Dm - floor(Dm);temp = (temp * 60) / 100;Dm = floor(Dm);Dm += temp;Dm = Dm /100;Dms = Dm;return Dms;}//*************绘制线路显示出路线int count1=0;bool bFirst = true;double xTemp;double yTemp;void CGpsDataView::DrawPoint(double X, double Y){Sleep(100);//X = (X - floor(X))*100;//Y = (Y - floor(Y))*100;if (bFirst){xTemp=X;yTemp=Y;bFirst=false;}CDC *pDC=GetDC();CPen pen(PS_SOLID,3,RGB(255,20,20));CPen *pOldPen;CBrush *pOldBrush;CBrush *pBrush=CBrush::FromHandle( (HBRUSH)GetStockObject(NULL_BRUSH) );pOldPen=pDC->SelectObject(&pen);pOldBrush=pDC->SelectObject(pBrush);int a=(int)(100.0-(X-xTemp)*800.0);int b=(int)(100.0+(Y-yTemp)*800.0);//绘制点显示路径pDC->Ellipse(a,b,a+5,b+5);//计数count1=count1+1;pDC->SelectObject( pOldBrush );pDC->SelectObject( pOldPen );CString str;str.Format("%.1f,%.1f,%d,%d,%d",X-xTemp,Y-yTemp,a,b,count1);pDC->TextOut(10,10,str);}。
GPS模拟C语言
GPS模拟C语言第一篇:GPS模拟C语言GPS模拟# include # include # includeusing namespace std;ifstream fin(“1.txt”);//ofstream fout(“data_out.txt”);// 1 double x[5] = {-1, 0, 300, 0, 300};double y[5] = {-1, 450, 450, 0, 0};double t[5];double A, B, D,c = 2982000, p, r;double pi = 3.141592653;double xx, yy;//三角形算法void cal(int sign, double t1, double t2, double x1, double y1, double x2, double y2, double px, double py){double tt1 = c * t1, tt2 = c * t2;double q, ac;A = x2 *(x1*x1 + y1*y1x1 *(x2*x2 + y2*y2tt1*tt1)tt2*tt2);D = tt1 *(x2*x2 + y2*y2tt2 *(x1*x1 + y1*y1ac;r =(x1*x1 + y1*y10)< 1e-6){switch(h){case 1:cal(-1, t[2], t[4], 300, 0, 300,-450, 0, 450);break;case 2: cal(-1, t[1], t[3],-300, 0,-300,-450,300, 450);break;case 3: cal(1, t[1], t[2], 0, 450, 300, 450, 0, 0);break;case 4: cal(1, t[1], t[2],-300, 450, 0, 450, 300, 0);break;}break;} } system(“pause”);return 0;声源定位#include #include using namespace std;#define Max 50 int N=10;double xi[10];double yi[10];double ti[10][3];double det(double a[Max][Max],int n){ int i,j,start;double k,temp,result=1;for(start=0;start<=n-2;start++){i=1;while(a[start][start]==0&&start+i<=n-1){for(j=start;j<=n-1;j++){temp=-1*a[start][j];a[start][j]=a[start+i][j];a[start+i][j]=temp;}i++;}if(start+i==n)continue;for(i=start+1;i<=n-1;i++){k=a[i][start]/a[start][start];for(j=start;j<=n-1;j++)a[i][j]=a[i][j]-k*a[start][j];} } for(i=0;i<=n-1;i++)result*=a[i][i];return result;} int equalation(double a[Max][Max+1],double r[Max],int n){ double det(double a[Max][Max],int n);double det0[Max][Max],det1[Max][Max];int i,j,k;for(i=0;i<=n-1;i++)for(j=0;j<=n-1;j++)det0[i][j]=a[i][j];if(det(det0,n)==0)return 0;for(k=0;k<=n-1;k++){for(i=0;i<=n-1;i++)for(j=0;j<=n-1;j++){det0[i][j]=a[i][j];det1[i][j]=a[i][j];}for(i=0;i<=n-1;i++)det1[i][k]=a[i][n];r[k]=det(det1,n)/det(det0,n);} return 1;} double sqr(double x){ return x*x;} double g(double x,double y,double c,double xi,double yi,double ti){ return sqr(xi-x)+sqr(yi-y)-sqr(c*ti);} double fx(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum+=g(x,y,c,xi[i],yi[i],ti[i][k-1])*(xi[i]-x);return sum;} double fy(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum+=g(x,y,c,xi[i],yi[i],ti[i][k-1])*(yi[i]-y);return sum;} double fc(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum+=g(x,y,c,xi[i],yi[i],ti[i][k-1])*sqr(ti[i][k-1]);return sum;} double fxx(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*sqr(xi[i]-x)-g(x,y,c,xi[i],yi[i],ti[i][k-1]);return sum;} double fxy(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*(yi[i]-y)*(xi[i]-x);return sum;} double fxc(doublex,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++) sum=sum-2*c*sqr(ti[i][k-1])*(xi[i]-x);return sum;} double fyx(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*(xi[i]-x)*(yi[i]-y);return sum;} double fyy(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*sqr(yi[i]-y)-g(x,y,c,xi[i],yi[i],ti[i][k-1]);return sum;} double fyc(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*c*sqr(ti[i][k-1])*(yi[i]-y);return sum;} double fcx(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*(xi[i]-x)*sqr(ti[i][k-1]);return sum;} double fcy(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*(yi[i]-y)*sqr(ti[i][k-1]);return sum;} double fcc(double x,double y,double c,int k){ int i;double sum=0;for(i=0;i<=N-1;i++)sum=sum-2*c*sqr(sqr(ti[i][k-1]));return sum;} int main(){ int i=0,k;double x,y,c,x0,y0,c0;double a[Max][Max+1],r[Max];freopen(“1.txt”, “r”, stdin);freopen(“1_out.txt”, “w”, stdout);for(i=0;i<=9;i++){} cin>>xi[i]>>yi[i];xi[i] /= 10;yi[i] /= 10;cin>>ti[i][0]>>ti[i][1]>>ti[i][2];for(k=1;k<=3;k++){ cin>>x> >y;c=0.2;do {x0=x;y0=y;c0=c;i++;a[0][0]=fxx(x,y,c,k);a[0][1]=fxy(x,y,c,k);a[0][2]=fxc(x,y,c,k);a[1][0]=fyx(x,y,c,k);a[1][1]=fyy(x,y,c,k);a[1][2]=fyc(x,y,c,k);a[2][0]=fcx(x, y,c,k);a[2][1]=fcy(x,y,c,k);a[2][2]=fcc(x,y,c,k);a[0][3]=x*a[0][0]+y*a[ 0][1]+c*a[0][2]-fx(x,y,c,k);a[1][3]=x*a[1][0]+y*a[1][1]+c*a[1][2]-fy(x,y,c,k);a[2][3]=x*a[2][0]+y*a[2][1]+c*a[2][2]-fc(x,y,c,k);if(equalation(a,r,3)==0){cout<return 0;}x=r[0];y=r[1];c=r[2];} while(abs(x-x0)+abs(y-y0)+abs(c-c0)>=1e-6);cout<<<<第二篇:C语言模拟ATM机一、实验目的通过设计一个ATM机模拟操作的程序,全面运用课程的主要知识点,巩固对模块化程序设计、文件操作的理解,提高软件编程能力。
坐标转换源代码
坐标转换源代码// Convert.cpp : implementation file//#include "stdafx.h"#include "坐标转换.h"#include "Convert.h"#include "Converting.h"#include "zbxtsz.h"#include "gybl.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif///////////////////////////////////////////////////////////////////// ////////// CConvert dialogCConvert::CConvert(CWnd* pParent /*=NULL*/): CDialog(CConvert::IDD, pParent){//{{AFX_DATA_INIT(CConvert)m_s21 = -1;m_s22 = -1;m_s23 = -1;m_s24 = -1;m_s25 = -1;m_s26 = -1;m_s27 = -1;m_New_Zyzwx = 0.0;m_Zyzwx = 0.0;//}}AFX_DATA_INIT}void CConvert::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CConvert)DDX_Control(pDX, IDC_NEW_Zyzwx, m_C_New_Zyzwx);DDX_Control(pDX, IDC_Zyzwx, m_C_Zyzwx);DDX_Control(pDX, IDC_ZBXT, m_Zbxt);DDX_Control(pDX, IDC_New_ZBXT, m_New_Zbxt);DDX_Control(pDX, IDC_Txfs1, m_Txfs1);DDX_Control(pDX, IDC_a21, m_c21);DDX_Control(pDX, IDC_a22, m_c22);DDX_Control(pDX, IDC_a23, m_c23);DDX_Control(pDX, IDC_a24, m_c24);DDX_Control(pDX, IDC_a25, m_c25);DDX_Control(pDX, IDC_a26, m_c26);DDX_Control(pDX, IDC_a27, m_c27);DDX_Radio(pDX, IDC_a21, m_s21);DDX_Radio(pDX, IDC_a22, m_s22);DDX_Radio(pDX, IDC_a23, m_s23);DDX_Radio(pDX, IDC_a24, m_s24);DDX_Radio(pDX, IDC_a25, m_s25);DDX_Radio(pDX, IDC_a26, m_s26);DDX_Radio(pDX, IDC_a27, m_s27);DDX_Text(pDX, IDC_NEW_Zyzwx, m_New_Zyzwx);DDX_Text(pDX, IDC_Zyzwx, m_Zyzwx);DDX_Control(pDX, IDC_Grid1, m_Grid1);DDX_Control(pDX, IDC_Grid2, m_Grid2);DDX_Control(pDX, IDC_Grid3, m_Grid3);DDX_Control(pDX, IDC_Grid4, m_Grid4);DDX_Control(pDX, IDC_Grid5, m_Grid5);DDX_Control(pDX, IDC_Grid6, m_Grid6);DDX_Control(pDX, IDC_Grid7, m_Grid7);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CConvert, CDialog)//{{AFX_MSG_MAP(CConvert)ON_BN_CLICKED(IDC_Dyzbxt, OnDyzbxt)ON_BN_CLICKED(IDC_Txfs1, OnTxfs1)ON_BN_CLICKED(IDC_Txfs2, OnTxfs2)ON_BN_CLICKED(IDC_Txfs3, OnTxfs3)ON_BN_CLICKED(IDC_Txfs4, OnTxfs4)ON_BN_CLICKED(IDC_a21, Ona21)ON_BN_CLICKED(IDC_a22, Ona22)ON_BN_CLICKED(IDC_a23, Ona23)ON_BN_CLICKED(IDC_a24, Ona24)ON_BN_CLICKED(IDC_a25, Ona25)ON_BN_CLICKED(IDC_a26, Ona26)ON_BN_CLICKED(IDC_a27, Ona27)ON_CBN_SELCHANGE(IDC_New_ZBXT, OnSelchangeNewZBXT)ON_CBN_SELCHANGE(IDC_ZBXT, OnSelchangeZbxt)ON_BN_CLICKED(ID_Insert, OnInsert)ON_BN_CLICKED(ID_Delete, OnDelete)ON_BN_CLICKED(ID_change, Onchange)ON_BN_CLICKED(ID_Input, OnInput)ON_BN_CLICKED(ID_Output, OnOutput)//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////// ////////// CConvert message handlersvoid CConvert::OnDyzbxt(){CZbxtSz dlg;dlg.DoModal();int i,j;i=m_Zbxt.GetCount();for (j=0;j{ m_Zbxt.DeleteString(0);m_New_Zbxt.DeleteString(0);}GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){m_Zbxt.AddString(GyBl.Zbxt_work->XtName);m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);GyBl.Zbxt_work=GyBl.Zbxt_work->next;}SzzbxtName();}BOOL CConvert::OnInitDialog(){int i;k_mode=1;CDialog::OnInitDialog();CString sHeading;sHeading = _T("序号|点号 | 转换前 X 坐标 | 转换前Y 坐标 | 转换后 X 坐标 | 转换后 Y 坐标 ");m_Grid1.SetFormatString ( sHeading);sHeading = _T("序号| 点号 | 纬度 |经度 | 转换后 X 坐标 | 转换后 Y 坐标 ");m_Grid2.SetFormatString ( sHeading);sHeading = _T("序号| 点号 | X 坐标 | Y 坐标 | 纬度 | 经度 "); m_Grid3.SetFormatString ( sHeading);sHeading = _T("序号| 点号 | B | L | H |X|Y|Z");m_Grid4.SetFormatString ( sHeading);sHeading = _T("序号| 点号 | X | Y | Z |B|L|H");m_Grid5.SetFormatString ( sHeading);for( i = 1; i < 8; i++ ){ m_Grid4.SetColWidth(i,1500);m_Grid5.SetColWidth(i,1500);}sHeading = _T("序号| 点号 | 转换前 X 坐标 | 转换前 Y 坐标 | 转换后 X 坐标 | 转换后 Y 坐标 ");m_Grid6.SetFormatString ( sHeading);sHeading = _T("序号| 点号 | 转换前 X 坐标 | 转换前 Y 坐标 | 转换前 Z 坐标 | 转换后 X 坐标 | 转换后 Y 坐标 |转换前 Y 坐标 ");m_Grid7.SetFormatString ( sHeading);m_Grid1.SetAllowUserResizing(1);m_Grid2.SetAllowUserResizing(1);m_Grid3.SetAllowUserResizing(1);m_Grid4.SetAllowUserResizing(1);m_Grid5.SetAllowUserResizing(1);m_Grid6.SetAllowUserResizing(1);m_Grid7.SetAllowUserResizing(1);m_Txfs1.SetCheck(1);Szzhfs();GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){m_Zbxt.AddString(GyBl.Zbxt_work->XtName);m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);GyBl.Zbxt_work=GyBl.Zbxt_work->next;}SzzbxtName();ReadData();return TRUE; // return TRUE unless you set the focus to a co ntrol// EXCEPTION: OCX Property Pages should return FALSE}void CConvert::OnTxfs1(){GyBl.WorkData.Mode=1;Szzhfs();}void CConvert::OnTxfs2(){GyBl.WorkData.Mode=2;Szzhfs();}void CConvert::OnTxfs3(){GyBl.WorkData.Mode=3;Szzhfs();}void CConvert::OnTxfs4(){GyBl.WorkData.Mode=4;Szzhfs();}void CConvert::Szzhfs(){m_c21.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode= =2);m_c22.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode= =2);m_c23.EnableWindow(GyBl.WorkData.Mode==1||GyBl.WorkData.Mode= =2);m_c24.EnableWindow(GyBl.WorkData.Mode==3);m_c25.EnableWindow(GyBl.WorkData.Mode==3);m_c26.EnableWindow(GyBl.WorkData.Mode==4);m_c27.EnableWindow(GyBl.WorkData.Mode==4);Szzbxt();}CConvert::Szzbxt(){m_Zbxt.EnableWindow( ((GyBl.WorkData.Mode==1||GyBl.WorkData.Mode= =2)&&(GyBl.WorkData.Ys[1]+GyBl.WorkData.Ys[2]+GyBl.WorkData.Ys [3]>=1))|| ( (GyBl.WorkData.Mode==3)&&(GyBl.WorkData.Ys[4]+GyBl.WorkData.Ys[5])));m_New_Zbxt.EnableWindow( (GyBl.WorkData.Mode==1||GyBl.WorkData.Mo de==2)&&(GyBl.WorkData.Ys[1]==1) );m_C_New_Zyzwx.EnableWindow( ((GyBl.WorkData.Mode==1||GyBl.WorkDat a.Mode==2)&&(GyBl.WorkData.Ys[1]==1)) &&(!strcmp(GyBl.WorkData.New_Zbx t.Xtmode,"系统保留")) );if (strcmp(GyBl.WorkData.Zbxt.Xtmode,"系统保留")==0){m_C_Zyzwx.EnableWindow((GyBl.WorkData.Mode==1||GyBl.WorkDa ta.Mode==2)&&((GyBl.WorkData.Ys[1]==1||GyBl.WorkData.Ys[3]==1||GyBl. WorkData.Ys[2]==1) ));}elsem_C_Zyzwx.EnableWindow(FALSE);m_c21.SetCheck(GyBl.WorkData.Ys[1]==1);m_c22.SetCheck(GyBl.WorkData.Ys[2]==1);m_c23.SetCheck(GyBl.WorkData.Ys[3]==1);m_c24.SetCheck(GyBl.WorkData.Ys[4]==1);m_c25.SetCheck(GyBl.WorkData.Ys[5]==1);m_c26.SetCheck(GyBl.WorkData.Ys[6]==1);m_c27.SetCheck(GyBl.WorkData.Ys[7]==1);Szinput();}void CConvert::Ona21()GyBl.WorkData.Ys[1]=1;if (GyBl.WorkData.Ys[1]==1){GyBl.WorkData.Ys[2]=GyBl.WorkData.Ys[3]=0;}Szzbxt();}void CConvert::Ona22(){GyBl.WorkData.Ys[2]=1;if (GyBl.WorkData.Ys[2]==1){GyBl.WorkData.Ys[1]=GyBl.WorkData.Ys[3]=0;}Szzbxt();}void CConvert::Ona23(){GyBl.WorkData.Ys[3]=1;if (GyBl.WorkData.Ys[3]==1){GyBl.WorkData.Ys[1]=GyBl.WorkData.Ys[2]=0;}Szzbxt();}void CConvert::Ona24(){GyBl.WorkData.Ys[4]=1;if (GyBl.WorkData.Ys[4]==1) GyBl.WorkData.Ys[5]=0; Szzbxt();}void CConvert::Ona25(){GyBl.WorkData.Ys[5]=1;if (GyBl.WorkData.Ys[5]==1) GyBl.WorkData.Ys[4]=0; Szzbxt();}void CConvert::Ona26()GyBl.WorkData.Ys[6]=1;if (GyBl.WorkData.Ys[6]==1) GyBl.WorkData.Ys[7]=0;Szzbxt();}void CConvert::Ona27(){GyBl.WorkData.Ys[7]=1;if (GyBl.WorkData.Ys[7]==1) GyBl.WorkData.Ys[6]=0;Szzbxt();}CConvert::SzzbxtName(){int i;i=0;GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){ i++;if (strcmp(GyBl.Zbxt_work->XtName,GyBl.WorkData.Zbxt.XtName)==0) break;GyBl.Zbxt_work=GyBl.Zbxt_work->next;}if (GyBl.Zbxt_work==NULL){i++;GyBl.NewZbxt();strcpy(GyBl.Zbxt_work->XtName,GyBl.WorkData.Zbxt.XtName);strcpy(GyBl.Zbxt_work->Xtmode,GyBl.WorkData.Zbxt.Xtmode);GyBl.Zbxt_work->Ra=GyBl.WorkData.Zbxt.Ra;GyBl.Zbxt_work->Bl=GyBl.WorkData.Zbxt.Bl;GyBl.Zbxt_work->Bl_num=GyBl.WorkData.Zbxt.Bl_num;GyBl.Zbxt_work->Zyzwx=GyBl.WorkData.Zbxt.Zyzwx;GyBl.Zbxt_work->Tyg=GyBl.WorkData.Zbxt.Tyg;GyBl.Zbxt_work->Xp=GyBl.WorkData.Zbxt.Xp;GyBl.Zbxt_work->Yp=GyBl.WorkData.Zbxt.Yp;m_Zbxt.AddString(GyBl.Zbxt_work->XtName);}m_Zbxt.SetCurSel(i-1);strcpy(GyBl.WorkData.Zbxt.Xtmode,GyBl.Zbxt_work->Xtmode);GyBl.WorkData.Zbxt.Ra=GyBl.Zbxt_work->Ra;GyBl.WorkData.Zbxt.Bl=GyBl.Zbxt_work->Bl;GyBl.WorkData.Zbxt.Bl_num=GyBl.Zbxt_work->Bl_num;GyBl.WorkData.Zbxt.Zyzwx=GyBl.Zbxt_work->Zyzwx;GyBl.WorkData.Zbxt.Tyg=GyBl.Zbxt_work->Tyg;GyBl.WorkData.Zbxt.Xp=GyBl.Zbxt_work->Xp;GyBl.WorkData.Zbxt.Yp=GyBl.Zbxt_work->Yp;m_Zyzwx=GyBl.WorkData.Zbxt.Zyzwx;i=0;GyBl.Zbxt_work= GyBl.Zbxt_head;while (GyBl.Zbxt_work!=NULL){ i++;if (strcmp(GyBl.Zbxt_work->XtName,GyBl.WorkData.New_Zbxt.XtName) ==0) break;GyBl.Zbxt_work=GyBl.Zbxt_work->next;}if (GyBl.Zbxt_work==NULL){i++;GyBl.NewZbxt();strcpy(GyBl.Zbxt_work->XtName,GyBl.WorkData.New_Zbxt.XtName);strcpy(GyBl.Zbxt_work->Xtmode,GyBl.WorkData.New_Zbxt.Xtmode);GyBl.Zbxt_work->Ra=GyBl.WorkData.New_Zbxt.Ra;GyBl.Zbxt_work->Bl=GyBl.WorkData.New_Zbxt.Bl;GyBl.Zbxt_work->Bl_num=GyBl.WorkData.New_Zbxt.Bl_num;GyBl.Zbxt_work->Zyzwx=GyBl.WorkData.New_Zbxt.Zyzwx;GyBl.Zbxt_work->Tyg=GyBl.WorkData.New_Zbxt.Tyg;GyBl.Zbxt_work->Xp=GyBl.WorkData.New_Zbxt.Xp;GyBl.Zbxt_work->Yp=GyBl.WorkData.New_Zbxt.Yp;m_New_Zbxt.AddString(GyBl.Zbxt_work->XtName);}m_New_Zbxt.SetCurSel(i-1);strcpy(GyBl.WorkData.New_Zbxt.Xtmode,GyBl.Zbxt_work->Xtmode);GyBl.WorkData.New_Zbxt.Ra=GyBl.Zbxt_work->Ra;GyBl.WorkData.New_Zbxt.Bl=GyBl.Zbxt_work->Bl;GyBl.WorkData.New_Zbxt.Bl_num=GyBl.Zbxt_work->Bl_num;GyBl.WorkData.New_Zbxt.Zyzwx=GyBl.Zbxt_work->Zyzwx;GyBl.WorkData.New_Zbxt.Tyg=GyBl.Zbxt_work->Tyg;GyBl.WorkData.New_Zbxt.Xp=GyBl.Zbxt_work->Xp;GyBl.WorkData.New_Zbxt.Yp=GyBl.Zbxt_work->Yp;m_New_Zyzwx=GyBl.WorkData.New_Zbxt.Zyzwx;CWnd::UpdateData(FALSE);Szzbxt();}void CConvert::OnSelchangeNewZBXT(){CString str;m_New_Zbxt.GetLBText(m_New_Zbxt.GetCurSel(),str); strcpy(GyBl.WorkData.New_Zbxt.XtName,str);SzzbxtName();}void CConvert::OnSelchangeZbxt(){CString str;m_Zbxt.GetLBText(m_Zbxt.GetCurSel(),str);strcpy(GyBl.WorkData.Zbxt.XtName,str);SzzbxtName();}CConvert::Szinput(){m_Grid1.ShowWindow(FALSE);m_Grid2.ShowWindow(FALSE);m_Grid3.ShowWindow(FALSE);m_Grid4.ShowWindow(FALSE);m_Grid5.ShowWindow(FALSE);m_Grid6.ShowWindow(FALSE);m_Grid7.ShowWindow(FALSE);if (GyBl.WorkData.Mode==1||GyBl.WorkData.Mode==2) {m_Grid1.ShowWindow(GyBl.WorkData.Ys[1]==1);m_Grid2.ShowWindow(GyBl.WorkData.Ys[2]==1);m_Grid3.ShowWindow(GyBl.WorkData.Ys[3]==1);if(GyBl.WorkData.Ys[1]==1) k_mode=1;if(GyBl.WorkData.Ys[2]==1) k_mode=2;if(GyBl.WorkData.Ys[3]==1) k_mode=3;}if (GyBl.WorkData.Mode==3){m_Grid4.ShowWindow(GyBl.WorkData.Ys[4]==1);m_Grid5.ShowWindow(GyBl.WorkData.Ys[5]==1);if(GyBl.WorkData.Ys[4]==1) k_mode=4;if(GyBl.WorkData.Ys[5]==1) k_mode=5;}if (GyBl.WorkData.Mode==4){m_Grid6.ShowWindow(GyBl.WorkData.Ys[6]==1);m_Grid7.ShowWindow(GyBl.WorkData.Ys[7]==1);if(GyBl.WorkData.Ys[6]==1) k_mode=6;if(GyBl.WorkData.Ys[7]==1) k_mode=7;}}BEGIN_EVENTSINK_MAP(CConvert, CDialog)//{{AFX_EVENTSINK_MAP(CConvert)ON_EVENT(CConvert, IDC_Grid1, -600 /* Click */, OnClickGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid2, -600 /* Click */, OnClickGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid3, -600 /* Click */, OnClickGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid4, -600 /* Click */, OnClickGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid5, -600 /* Click */, OnClickGrid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid1, 71 /* EnterCell */, OnEnterCell Grid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid2, 71 /* EnterCell */, OnEnterCell Grid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid3, 71 /* EnterCell */, OnEnterCell Grid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid4, 71 /* EnterCell */, OnEnterCell Grid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid5, 71 /* EnterCell */, OnEnterCell Grid1, VTS_NONE)ON_EVENT(CConvert, IDC_Grid1, -603 /* KeyPress */, OnKeyPress Grid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid2, -603 /* KeyPress */, OnKeyPress Grid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid3, -603 /* KeyPress */, OnKeyPress Grid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid4, -603 /* KeyPress */, OnKeyPress Grid1, VTS_PI2)ON_EVENT(CConvert, IDC_Grid5, -603 /* KeyPress */, OnKeyPress Grid1, VTS_PI2)//}}AFX_EVENTSINK_MAPEND_EVENTSINK_MAP()void CConvert::OnClickGrid1(){TransferValue (FALSE);}void CConvert::OnEnterCellGrid1(){TransferValue (FALSE);}void CConvert::OnKeyPressGrid1(short FAR* KeyAscii){switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch ( (int) * KeyAscii) {case VK_BACK : //Backspace - delete the last charact erm_GridData .Delete (m_GridData .Get Length ()-1,1);break;case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':case '0':m_GridData = m_GridData + (TCHAR *) KeyAscii;break;case '.':if ((m_GridData.Find('.')==-1))m_GridData = m_GridData + (TCHAR *) KeyAscii;break;case '-':if (m_GridData=="")m_GridData = m_GridData + (TCHAR *) KeyAscii;break;default :if (m_Grid->GetCol()==1)m_GridData = m_GridData + (TCHAR *) KeyAscii;break;}TransferValue (TRUE);}BOOL CConvert::TransferValue(BOOL ToGrid){CString sText;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}if (ToGrid){ //Transfer value to Grid from Edit Boxswitch (k_mode){case 1:case 2:case 3:if (m_Grid->GetCol()<4) m_Grid->SetText(m_GridData);break;case 4:case 5:if (m_Grid->GetCol()<5) m_Grid->SetText(m_GridData);break;}} else {m_GridData = m_Grid->GetText ();m_Grid->SetBackColorSel(RGB(0,255,255));m_Grid->SetForeColor(RGB(255,0,0));}return TRUE;}void CConvert::OnInsert(){int i,j,k;CString str;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch (k_mode){case 1:case 2:case 3:i=m_Grid->GetRow();m_Grid->SetRows(m_Grid->GetRows()+1);for (j=m_Grid->GetRows()-1;j>i+1;j--){for (k=1;k<=5;k++){m_Grid->SetCol(k); m_Grid->SetRow(j-1); str=m_Grid-> GetText();m_Grid->SetRow(j); m_Grid->SetTe xt(str);}}str=""; m_Grid->SetCol(1);m_Grid->SetRow(i+ 1);m_Grid->SetText(str);m_Grid->SetCol(2);m_Grid->SetText(str);m_Grid->SetCol(3);m_Grid->Set Text(str);m_Grid->SetCol(4);m_Grid->Set Text(str);m_Grid->SetCol(5);m_Grid->Set Text(str);break;case 4:case 5:i=m_Grid->GetRow();m_Grid->SetRows(m_Grid->GetRows()+1);for (j=m_Grid->GetRows()-1;j>i+1;j--){for (k=1;k<=7;k++){m_Grid->SetCol(k); m_Grid->SetRow(j-1); str=m_Grid-> GetText();m_Grid->SetRow(j); m_Grid->SetTe xt(str);}}str=""; m_Grid->SetCol(1);m_Grid->SetRow(i+ 1);m_Grid->SetText(str);m_Grid->SetCol(2);m_Grid->SetText(str);m_Grid->SetCol(3);m_Grid->Set Text(str);m_Grid->SetCol(4);m_Grid->Set Text(str);m_Grid->SetCol(5);m_Grid->Set Text(str);m_Grid->SetCol(6);m_Grid->Set Text(str);m_Grid->SetCol(7);m_Grid->Set Text(str);break;}}void CConvert::OnDelete(){int i,j,k;CString str;switch (k_mode){case 1:m_Grid=&m_Grid1;break;case 2:m_Grid=&m_Grid2;break;case 3:m_Grid=&m_Grid3;break;case 4:m_Grid=&m_Grid4;break;case 5:m_Grid=&m_Grid5;break;}switch (k_mode){case 1:case 2:case 3:i=m_Grid->GetRow();if (i==0) break;m_Grid->SetCol(1); m_Grid->SetRow(i); str=m _Grid->GetText();str="确认删除 "+str;if (AfxMessageBox(str,MB_YESNO)==IDYES){for (j=i+1;jGetRows();j++){for (k=1;k<=5;k++){m_Grid->SetCol(k); m_Grid->SetRow(j); str=m_Grid ->GetText();m_Grid->SetRow(j-1); m_Grid->Se tText(str);}}m_Grid->SetRows(m_Grid->GetRows()-1);}break;case 4:case 5:i=m_Grid->GetRow();if (i==0) break;m_Grid->SetCol(1); m_Grid->SetRow(i); str=m _Grid->GetText();str="确认删除 "+str;if (AfxMessageBox(str,MB_YESNO)==IDYES){for (j=i+1;jGetRows();j++){for (k=1;k<=7;k++){m_Grid->SetCol(k); m_Grid->SetRow(j); str=m_Grid ->GetText();m_Grid->SetRow(j-1); m_Grid->Se tText(str);}}m_Grid->SetRows(m_Grid->GetRows()-1);}break;}}void CConvert::OnOK(){// TODO: Add extra validation hereWriteData();CDialog::OnOK();}double CConvert::CallL0(double l,int mode){double d0,l0;d0=l*180.0/PI;// double xxx;l0=0;if (mode==0) GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;else GyBl.Zbxt_work= &GyBl.WorkData.New_Zbxt;//中央子午线计算if (strcmp(GyBl.Zbxt_work->Xtmode,"自定义坐标系统")==0){l0=GyBl.Zbxt_work->Zyzwx;l0=Deg(l0);// xxx=GyBl.Zbxt_work->Yp;}else{// xxx=500000.000;{// int tt;// 3度 6度计算CWnd::UpdateData(TRUE);if (mode==0)l0=m_Zyzwx;else l0=m_New_Zyzwx;}}l0=l0 *PI/180;// vSetSystem(WorkSpaceData.Zbxt.Ra,1/WorkSpaceData.Zbxt.Bl,0,l0,0,xx x,1);return l0;}double CConvert::Deg(double a2){double d;double du,fen,miao;double nn;if (a2<0) { nn=-1;a2=-a2;} else nn=1;du=floor(a2); fen=floor((a2-du)*100);miao=((a2-du)*100-fen)*100;if (miao>=60) { fen++;miao=0;if (fen>=60) { fen=0;du++;}}d=du+fen/60+miao/3600;d=d*nn;return(d);}double CConvert::Dfm(double a2){double d;double du,fen,miao;double nn;if (a2<0) { nn=-1;a2=-a2;} else nn=1;du=floor(a2);fen=floor((a2-du)*60);miao=((a2-du)*60-fen)*60;if ((miao+0.00001)>=60) { fen++;miao=0;if (fen>=60) { fen=0;du++;}}d=du+fen/100+miao/10000;d=d*nn;return(d);}void CConvert::ReadData(){int i,j,k;char buf[100];double xx;m_Grid1.SetRows(1);m_Grid2.SetRows(1);m_Grid3.SetRows(1);m_Grid4.SetRows(1);m_Grid5.SetRows(1);m_Grid6.SetRows(1);m_Grid7.SetRows(1);FILE *in;in =fopen ("data","r+");if (in!=NULL){//m_Grid1fread(&j,sizeof(int),1,in);m_Grid1.SetRows(j);for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0) sprintf(buf,"%.3f",xx);else strcpy(buf,"");}m_Grid1.SetCol(k); m_Grid1.SetText(buf);}}//m_Grid2fread(&j,sizeof(int),1,in);m_Grid2.SetRows(j);for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0){if (k<=3)sprintf(buf,"%.8f",xx);elsesprintf(buf,"%.3f",xx);}else strcpy(buf,"");}m_Grid2.SetCol(k); m_Grid2.SetText(buf);}}//m_Grid3fread(&j,sizeof(int),1,in);m_Grid3.SetRows(j);for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);for (k=1;k<=5;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0){if (k<=3)sprintf(buf,"%.3f",xx);elsesprintf(buf,"%.8f",xx);}else strcpy(buf,"");}m_Grid3.SetCol(k); m_Grid3.SetText(buf);}}//m_Grid4fread(&j,sizeof(int),1,in);m_Grid4.SetRows(j);for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);for (k=1;k<=7;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0){if (k<=3)sprintf(buf,"%.8f",xx);elsesprintf(buf,"%.3f",xx);}else strcpy(buf,"");}m_Grid4.SetCol(k); m_Grid4.SetText(buf);}}//m_Grid5fread(&j,sizeof(int),1,in);m_Grid5.SetRows(j);for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);for (k=1;k<=7;k++){if (k==1) fread(buf,20,1,in);else { fread(&xx,sizeof(double),1,in);if (xx!=0){if ((k<=4)||(k==7))sprintf(buf,"%.3f",xx);elsesprintf(buf,"%.8f",xx);}else strcpy(buf,"");}m_Grid5.SetCol(k); m_Grid5.SetText(buf);}}fclose(in);}}void CConvert::WriteData(){int i,j,k;CString str;double xx;FILE *in;in =fopen ("data","w+");//m_Grid1j=m_Grid1.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);for (k=1;k<=5;k++){m_Grid1.SetCol(k); str=m_Grid1.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}//m_Grid2j=m_Grid2.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);for (k=1;k<=5;k++){m_Grid2.SetCol(k); str=m_Grid2.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}//m_Grid3j=m_Grid3.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);for (k=1;k<=5;k++){m_Grid3.SetCol(k); str=m_Grid3.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}//m_Grid4j=m_Grid4.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);for (k=1;k<=7;k++){m_Grid4.SetCol(k); str=m_Grid4.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}//m_Grid5j=m_Grid5.GetRows();fwrite(&j,sizeof(int),1,in);for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);for (k=1;k<=7;k++){m_Grid5.SetCol(k); str=m_Grid5.GetText();xx=atof(str);if (k==1) fwrite(str,20,1,in);else fwrite(&xx,sizeof(double),1,in);}}fclose(in);}void CConvert::Changejs(){CString str;double L0,L1;// double yyy,yyy1;double x1,y1,z1,x2,y2;double b1,l1,h1;//,b2,l2;int i,j;double MM;if (GyBl.WorkData.Mode==2)MM=0.9996;elseMM=1;switch (k_mode){case 1:L0=CallL0(0,0);j=m_Grid1.GetRows();for (i=0;i<J-1;I++){m_Grid1.SetRow(i+1);m_Grid1.SetCol(2); str=m_Grid1.GetText(); x1=atof(str); m_Grid1.SetCol(3); str=m_Grid1.GetText(); y1=atof(str);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->Yp,MM,GyBl.Zbxt_work->Tyg);Converting.XYBL(x1,y1,&b1,&l1);L1=CallL0(l1,1);GyBl.Zbxt_work= &GyBl.WorkData.New_Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L1,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work-> Yp,MM,GyBl.Zbxt_work->Tyg);Converting.BLXY(b1,l1,&x2,&y2);m_Grid1.SetCol(4); str.Format("%.3f",x2);m_Grid1.SetTex t(str);m_Grid1.SetCol(5); str.Format("%.3f",y2);m_Grid1.SetTex t(str);}break;case 2:j=m_Grid2.GetRows();for (i=0;i<J-1;I++){m_Grid2.SetRow(i+1);m_Grid2.SetCol(2); str=m_Grid2.GetText(); b1=Deg(atof (str));m_Grid2.SetCol(3); str=m_Grid2.GetText(); l1=Deg(atof (str));L1=CallL0(l1,0);//转换为幅度GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L1,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work-> Yp,MM,GyBl.Zbxt_work->Tyg);Converting.BLXY(b1*PI/180,l1*PI/180,&x2,&y2);m_Grid2.SetCol(4); str.Format("%.3f",x2);m_Grid2.SetText(str);m_Grid2.SetCol(5); str.Format("%.3f",y2);m_Grid2.SetTex t(str);}break;case 3:L0=CallL0(0,0);j=m_Grid3.GetRows();for (i=0;i<J-1;I++){m_Grid3.SetRow(i+1);m_Grid3.SetCol(2); str=m_Grid3.GetText(); x1=atof(s tr);m_Grid3.SetCol(3); str=m_Grid3.GetText(); y1=atof(s tr);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work-> Yp,MM,GyBl.Zbxt_work->Tyg);Converting.XYBL(x1,y1,&b1,&l1);m_Grid3.SetCol(4); str.Format("%.8f",Dfm(b1*180/PI));m_ Grid3.SetText(str);m_Grid3.SetCol(5); str.Format("%.8f",Dfm(l1*180/PI));m_ Grid3.SetText(str);}break;case 4:L0=CallL0(0,0);j=m_Grid4.GetRows();for (i=0;i<J-1;I++){m_Grid4.SetRow(i+1);m_Grid4.SetCol(2); str=m_Grid4.GetText(); b1=atof(s tr);m_Grid4.SetCol(3); str=m_Grid4.GetText(); l1=atof(s tr);m_Grid4.SetCol(4); str=m_Grid4.GetText(); h1=atof(s tr);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work-> Yp,MM,GyBl.Zbxt_work->Tyg);Converting.BLHXYZ(Deg(b1)*PI/180,Deg(l1)*PI/180,h1,&x1,&y1, &z1);m_Grid4.SetCol(5); str.Format("%.3f",x1);m_Grid4.SetTex t(str);m_Grid4.SetCol(6); str.Format("%.3f",y1);m_Grid4.SetTex t(str);m_Grid4.SetCol(7); str.Format("%.3f",z1);m_Grid4.SetTex t(str);}break;case 5:L0=CallL0(0,0);j=m_Grid5.GetRows();for (i=0;i<J-1;I++){m_Grid5.SetRow(i+1);m_Grid5.SetCol(2); str=m_Grid5.GetText(); x1=atof(s tr);m_Grid5.SetCol(3); str=m_Grid5.GetText(); y1=atof(s tr);m_Grid5.SetCol(4); str=m_Grid5.GetText(); z1=atof(s tr);GyBl.Zbxt_work= &GyBl.WorkData.Zbxt;// 长半径扁率中央纬度经度 Y 正家 X 增加比例投影高Converting.vSetSystem(GyBl.Zbxt_work->Ra,GyBl.Zbxt_work-> Bl,0,L0,GyBl.Zbxt_work->Xp,GyBl.Zbxt_work->。
坐标转换C#(Gcj02、wgs84、bd09互转)
坐标转换C#(Gcj02、wgs84、bd09互转)public class ConvertGPS{private static double pi = 3.1415926535897932384626;private static double a = 6378245.0;private static double ee = 0.00669342162296594323;private static double bd_pi = 3.14159265358979324 * 3000.0 / 180.0;static Boolean outOfChina(double lat, double lon){if (lon < 72.004 || lon > 137.8347)return true;if (lat < 0.8293 || lat > 55.8271)return true;return false;}static double transformLat(double x, double y){double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y+ 0.2 * Math.Sqrt(Math.Abs(x));ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0;ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0;return ret;}static double transformLon(double x, double y){double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1* Math.Sqrt(Math.Abs(x));ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0;ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0* pi)) * 2.0 / 3.0;return ret;}/*** 84 to ⽕星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System** @param lat* @param lon* @return*/public static PointLatLng gps84_To_Gcj02(PointLatLng Gpoint){if (outOfChina(t, Gpoint.Lng)){return new PointLatLng(0, 0);}double dLat = transformLat(Gpoint.Lng - 105.0, t - 35.0);double dLon = transformLon(Gpoint.Lng - 105.0, t - 35.0);double radLat = t / 180.0 * pi;double magic = Math.Sin(radLat);magic = 1 - ee * magic * magic;double sqrtMagic = Math.Sqrt(magic);dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);double mgLat = t + dLat;double mgLon = Gpoint.Lng + dLon;return new PointLatLng(mgLat, mgLon);}static PointLatLng transform(PointLatLng Gpoint){if (outOfChina(t, Gpoint.Lng)){return new PointLatLng(t, Gpoint.Lng);}double dLat = transformLat(Gpoint.Lng - 105.0, t - 35.0);double dLon = transformLon(Gpoint.Lng - 105.0, t - 35.0);double radLat = t / 180.0 * pi;double magic = Math.Sin(radLat);magic = 1 - ee * magic * magic;double sqrtMagic = Math.Sqrt(magic);dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);double mgLat = t + dLat;double mgLon = Gpoint.Lng + dLon;return new PointLatLng(mgLat, mgLon);}/*** * ⽕星坐标系 (GCJ-02) to 84 * * @param lon * @param lat * @return* */public static PointLatLng gcj02_To_Gps84(PointLatLng Gpoint){PointLatLng gps = transform(Gpoint);double lontitude = Gpoint.Lng * 2 - gps.Lng;double latitude = t * 2 - t;return new PointLatLng(latitude, lontitude);}/*** ⽕星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法将 GCJ-02 坐标转换成 BD-09 坐标** @param gg_lat* @param gg_lon*/public static PointLatLng gcj02_To_Bd09(PointLatLng Gpoint){double x = Gpoint.Lng, y = t;double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * bd_pi);double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * bd_pi);double bd_lon = z * Math.Cos(theta) + 0.0065;double bd_lat = z * Math.Sin(theta) + 0.006;return new PointLatLng(bd_lat, bd_lon);}/*** * ⽕星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 * * 将 BD-09 坐标转换成GCJ-02 坐标 * * @param * bd_lat * @param bd_lon * @return*/public static PointLatLng bd09_To_Gcj02(PointLatLng bdPoint){double x = bdPoint.Lng - 0.0065, y = t - 0.006;double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * bd_pi);double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * bd_pi);double gg_lon = z * Math.Cos(theta);double gg_lat = z * Math.Sin(theta);return new PointLatLng(gg_lat, gg_lon);}/*** (BD-09)-->84* @param bd_lat* @param bd_lon* @return*/public static PointLatLng bd09_To_Gps84(PointLatLng bdPoint){PointLatLng gcj02 = bd09_To_Gcj02(bdPoint);PointLatLng map84 = gcj02_To_Gps84(gcj02);return map84;}/*** 84-->(BD-09)* @param bd_lat* @param bd_lon* @return*/public static PointLatLng Gps84_To_bd09(PointLatLng gpsPoint){PointLatLng gcj02 = gps84_To_Gcj02(gpsPoint);PointLatLng bd09 = gcj02_To_Bd09(gcj02);return bd09;}}public class PointLatLng{public PointLatLng(double lat, double lng){Lat = lat;Lng = lng;}public double Lat { get; set; }public double Lng { get; set; }}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "stdlib.h"
//WGS-84椭球体参数
const double a=6378137.0;//长半轴
const double flattening=1/298.257223563;//扁率
const double delta=0.0000001;
typedef struct tagCRDCARTESIAN{
pct->upping=pctp->range*sin(pctp->elevation);
}
double x;
double y;
double z;
}CRDCARTESIAN;
typedef CRDCARTESIAN *PCRDCARTESIAN;
//笛卡尔坐标系
typedef struct tagCRDGEODETIC{
double longitude;
double latitude;
}CRDTOPOCENTRICPOLAR;
typedef CRDTOPOCENTRICPOLAR *PCRDTOPOCENTRICPOLAR;
//站心地平坐标系(极坐标形式)
//由笛卡尔坐标转换为大地坐标
void CartesianToGeodetic (PCRDGEODETIC pcg, PCRDC尔坐标
void GeodeticToCartesian (PCRDCARTESIAN pcc, PCRDGEODETIC pcg,
double dSemiMajorAxis, double dFlattening)
{
double e2;//第一偏心率的平方
}
//由站心地平直角坐标转换为站心地平极坐标
void TopocentricToTopocentricPolar (PCRDTOPOCENTRICPOLAR pctp,
PCRDTOPOCENTRIC pct)
{
pctp->range=sqrt(pct->northing*pct->northing+pct->easting*pct->easting+pct->upping*pct->upping);
//dSemiMajorAxis:参考椭球的长半轴;
//dFlattening:参考椭球的扁率。
//由笛卡尔坐标转换为站心地平坐标
void CartesianToTopocentric (PCRDTOPOCENTRIC pct,
PCRDCARTESIAN pcc,
PCRDCARTESIAN pccCenter,
pcc->y=(N+pcg->height)*cos(pcg->latitude)*sin(pcg->longitude);
pcc->z=(N*(1-e2)+pcg->height)*sin(pcg->latitude);
}
//由笛卡尔坐标转换为站心地平坐标
void CartesianToTopocentric (PCRDTOPOCENTRIC pct,
double height;
}CRDGEODETIC;
typedef CRDGEODETIC *PCRDGEODETIC;
//大地坐标系
typedef struct tagCRDTOPOCENTRIC{
double northing;
double easting;
double upping;
void GeodeticToCartesian (PCRDCARTESIAN pcc, PCRDGEODETIC pcg,
double dSemiMajorAxis, double dFlattening);
//pcc:指向所转换出的笛卡尔坐标的指针;
//pcg:指向待转换的大地坐标的指针;
pct->northing=-sin(pd->latitude)*cos(pd->longitude)*dx
-sin(pd->latitude)*sin(pd->longitude)*dy
+cos(pd->latitude)*dz;
pct->easting=-sin(pd->longitude)*dx
double dSemiMajorAxis,
double dFlattening);
//pct:指向所转换出的站心地平坐标的指针;
//pcc:指向待转换的笛卡尔坐标的指针;
//pccCenter:指向站心的笛卡尔坐标的指针;
//dSemiMajorAxis:参考椭球的长半轴;
//dFlattening:参考椭球的扁率。
dz=pcc->z-pccCenter->z;
PCRDGEODETIC pd;
pd=(PCRDGEODETIC)malloc(sizeof(CRDGEODETIC));
CartesianToGeodetic (pd,pccCenter,dSemiMajorAxis,dFlattening);
}CRDTOPOCENTRIC;
typedef CRDTOPOCENTRIC *PCRDTOPOCENTRIC;
//站心地平坐标系(线坐标形式)
typedef struct tagCRDTOPOCENTRICPOLAR{
double range;
double azimuth;
double elevation;
PCRDTOPOCENTRICPOLAR pctp)
{
pct->northing=pctp->range*cos(pctp->elevation)*cos(pctp->azimuth);
pct->easting=pctp->range*cos(pctp->elevation)*sin(pctp->azimuth);
double dSemiMajorAxis, double dFlattening);
//pcg:指向所转换出的大地坐标的指针;
//pcc:指向待转换的笛卡尔坐标的指针;
//dSemiMajorAxis:参考椭球的长半轴;
//dFlattening:参考椭球的扁率。
//由大地坐标转换为笛卡尔坐标
//由站心地平极坐标转换为站心地平直角坐标
void TopocentricPolarToTopocentric (PCRDTOPOCENTRIC pct,PCRDTOPOCENTRICPOLAR pctp);
//pct:指向所转换的站心地平坐标的指针;
//pctp:指向待转换的站心地平极坐标的指针;
while(1)
{
W=sqrt(1-e2*sin(B1)*sin(B1));
N1=dSemiMajorAxis/W;
B=atan((pcc->z+N1*e2*sin(B1))/sqrt(pcc->x*pcc->x+pcc->y*pcc->y));
if(fabs(B-B1)<delta)
+cos(pd->longitude)*dy;
pct->upping=cos(pd->latitude)*cos(pd->longitude)*dx
+cos(pd->latitude)*sin(pd->longitude)*dy
+sin(pd->latitude)*dz;
free(pd);
PCRDCARTESIAN pcc,
PCRDCARTESIAN pccCenter,
double dSemiMajorAxis,
double dFlattening)
{
double dx,dy,dz;
dx=pcc->x-pccCenter->x;
dy=pcc->y-pccCenter->y;
pctp->azimuth=atan(pct->easting/pct->northing);
pctp->elevation=asin(pct->upping/pctp->range);
}
//由站心地平极坐标转换为站心地平直角坐标
void TopocentricPolarToTopocentric (PCRDTOPOCENTRIC pct,
//由站心地平直角坐标转换为站心地平极坐标
void TopocentricToTopocentricPolar (PCRDTOPOCENTRICPOLAR pctp,
PCRDTOPOCENTRIC pct);
//pctp:指向所转换出的站心地平极坐标的指针;
//pct:指向待转换的站心地平坐标的指针;
#endif
源文件:
#include "CoordCovert.h"
#include "math.h"
void CartesianToGeodetic (PCRDGEODETIC pcg, PCRDCARTESIAN pcc,
double dSemiMajorAxis, double dFlattening)
break;
else
B1=B;
}
pcg->latitude=B;