Turn longitude and latitude to Kay lide K code

Source: Internet
Author: User
Tags comparison table

Because the GPS signal positions are longitude and latitude spherical coordinates, the State cannot directly reference them from a security perspective. Therefore, kailide gridded the coordinates of longitude and latitude to facilitate the navigation of the navigators, each grid unit represents a vertical direction of 0.1 seconds.

The specific format of the K-code is as follows:

1. The K code is a 9-digit code;

2. The K-Code divides the map into four parts for encoding. The central point is in the territory of the arashan left flag in the Mongolia Autonomous Region. the longitude and latitude are the longitude and latitude of 105 degrees 0 minutes 0 seconds; the latitude is 40 degrees 0 minutes 0 seconds.

3. draw a line in the east-west direction and the North-South direction respectively as the horizontal and vertical (xy) axes, then the 1st-bit K code of the First quadrant (that is, the block in the northeast direction) is 5, the first K codes in quadrant 2nd, 3, and 4 are 6, 7, and 8, respectively.

4. The 2-5th digit of the K code represents the coordinates of the East and the West, and the 6-9th digit represents the coordinates of the South and the North.

5. the K-code is a 34-digit number unique to Kay lide. (on the KlD K-code input page, note: 26 letters plus 10 Arabic numerals, remove unnecessary L and O 34 characters in total). The 34 hexadecimal number is arranged from left to right from low to high.

6. There are 4 K codes in the center, namely 500000000, 6uy1y0000, 7uy1yuy1y, and 80000uy1y. The K code representing the origin or the four quadrants of the central point. And X and Y-axis start coordinate 0 s orCodeThe value is 0000, the maximum coordinate of the X and Y axes in the negative direction is 1260000 seconds, or the code is uy1y.

The VC ++ code is as follows:

Kcode. h

# Ifndef _ character _ # DEFINE _ character struct {int iindex; tchar ckcode;} mykcode_t; # define kld_kcode_system34 # define sequence (40.0) # define kcode_center_lon (105.0) # define linear regression (double dlatlondu, double dlatlonfen, double dlatlonmiao, double & dlatlon); bool convertto34system (DWORD dwnumber, tchar * pkcode, bool bnegative); bool linear (DWORD dwnumber, tchar * pkcode, bool bnegative); // similar to convertto34system, bool kcodetozeropoint (double dlat, double dlon, tchar * pkcode, int ikcodesize) is implemented using a comparison table ); /* Call example: Double dlon = 0.0; double dlat = 0.0; tchar ctmpbuffer [2 * kocde_max_length + 2]; zeromemory (ctmpbuffer, sizeof (tchar) * (2 * kocde_max_length + 2); convertdufenmiaotodu (101.0, 7.0, 26.33, dlon); convertdufenmiaotodu (29.0, 39.0, 51.76, dlat); // convertdufenmiaotodu (40.0, 0.0, 0.0, dlat); // point test on the coordinate axis kcodetozeropoint (dlat, dlon, ctmpbuffer, 2 * kocde_max_length + 2); */# endif

Source code:

Kcode. cpp

# Include "stdafx. H "# include" kcode. H "mykcode_t gmykcode [kld_kcode_system] = {0, '0'}, {1, '1'}, {2, '2'}, {3, '3'}, {4, '4'}, {5, '5'}, {6, '6'}, {7, '7'}, {8, '8'}, {9, '9'}, {10, 'A'}, {11, 'B'}, {12, 'C'}, {13, 'D '}, {14, 'E'}, {15, 'F'}, {16, 'G'}, {17, 'H'}, {18, 'I'}, {19, 'J'}, {20, 'K'}, // No L {21, 'M'}, {22, 'n '}, // No character o {23, 'P'}, {24, 'q'}, {25, 'R'}, {26, 's'}, {27, 'T'}, {28, 'U'}, {29, 'V'}, {30, 'w'}, {31, 'x'}, {32, 'y'}, {33, 'Z'},}; bool convertdufenmiaotodu (double dlatlondu, double dlatlonfen, double dlatlonmiao, double & dlatlon) {bool Bret = true; // input validity judgment {} dlatlon = dlatlondu + (dlatlonfen + (dlatlonmiao/60.0)/60.0; return Bret;} bool convertto34system2 (DWORD dwnumber, tchar * pkcode, bool bnegative) {bool Bret = true; DWORD dwdivideby34 = dwnumber; int imodeof34 = 0; int icount = 0; int I = 0; // dwdivideby34= 1260000; do {Imodeof34 = dwdivideby34 % 34; dwdivideby34 = dwdivideby34/34; for (I = 0; I <kld_kcode_system; I ++) {If (imodeof34 = gmykcode [I]. iindex) {pkcode [icount] = gmykcode [I]. ckcode; icount ++; if (1 = icount & bnegative) {pkcode [0] -- ;} break ;}}while (dwdivideby34> 0); Return Bret ;} bool convertto34system (DWORD dwnumber, tchar * pkcode, bool bnegative) {bool Bret = true; DWORD dwdivideby34 = dwnumber; int imodeof34 = 0; Int icount = 0; do {imodeof34 = dwdivideby34 % 34; dwdivideby34 = dwdivideby34/34; If (imodeof34 <= 9) {pkcode [icount] = '0' + imodeof34 ;} else if (imodeof34 >=10 & imodeof34 <= 20) {pkcode [icount] = 'A' + (imodeof34-10 );} else if (imodeof34 >=21 & imodeof34 <= 22) {pkcode [icount] = 'M' + (imodeof34-21 );} else if (imodeof34> = 23 & imodeof34 <= 33) {pkcode [icount] = 'P' + (imodeof34-23);} icount ++; I F (1 = icount & bnegative) {pkcode [0] -- ;}} while (dwdivideby34> 0); Return Bret ;}/ ** description: ikcodesize contains the final null */bool kcodetozeropoint (double dlat, double dlon, tchar * pkcode, int ikcodesize) {bool Bret = true; DWORD dwtmplat = 0; DWORD dwtmplon = 0; bool bisnegative = false; tchar pkcodelat [kocde_max_length + 1]; tchar pkcodelon [kocde_max_length + 1]; // input validity judgment {If (ikcodesize <(2 * kocde_max_length + 1 )) {Return Bret;} If (null = pkcode) {Bret = false; return Bret;} zeromemory (pkcodelat, sizeof (tchar) * (kocde_max_length + 1 )); zeromemory (pkcodelon, sizeof (tchar) * (kocde_max_length + 1); If (null! = Pkcodelat) {double ddiff = (dlat-kcode_center_lat); If (ddiff <0) {bisnegative = true; ddiff =-ddiff; dwtmplat = (DWORD) (ddiff * 3600) * 10); // in 0.1 seconds, dwtmplat = kcode_x_y_max_nagative-dwtmplat;} else {bisnegative = false; dwtmplat = (DWORD) (ddiff * 3600) * 10 ); // In the unit of 0.1 seconds} convertto34system (dwtmplat, pkcodelat, bisnegative);} If (null! = Pkcodelon) {double ddiff = (dlon-kcode_center_lon); If (ddiff <0) {bisnegative = true; ddiff =-ddiff; dwtmplon = (DWORD) (ddiff * 3600) * 10); // The unit is 0.1 seconds. dwtmplon = kcode_x_y_max_nagative-dwtmplon;} else {bisnegative = false; dwtmplon = (DWORD) (ddiff * 3600) * 10 ); // In the unit of 0.1 seconds} convertto34system (dwtmplon, pkcodelon, bisnegative);} If (kcode_center_lat = dlat | kcode_center_lon = dlon) {If (kernel = dlat & kcode_center_lon = dlon) {pkcode [0] = '5';} else if (kcode_center_lat = dlat) {If (dlon> kcode_center_lon) {pkcode [0] = '6';} else {pkcode [0] = '8';} else if (kcode_center_lon = dlon) {If (dlat> kcode_center_lat) {pkcode [0] = '5';} else {pkcode [0] = '7' ;}} else {If (dlat> kcode_center_lat) {If (dlon> kcode_center_lon) {pkcode [0] = '5';} else {pkcode [0] = '6' ;}} else {If (dlon> kcode_center_lon) {pkcode [0] = '8';} else {pkcode [0] = '7' ;}}} wcscat_s (pkcode, ikcodesize, pkcodelon); wcscat_s (pkcode, ikcodesize, pkcodelat); printf ("K code is: % s \ r \ n", pkcode); Return Bret ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.