Conversions between coordinate systems and between Coordinate Systems

Source: Internet
Author: User

Conversions between coordinate systems and between Coordinate Systems
I. Coordinate Systems

Currently, map development is inseparable from positioning and Coordinate System Selection and conversion. Therefore, it is necessary to briefly describe it.

World Earth coordinates (WGS84)

1. The international standard is a coordinate system established for the use of GPS, which can obtain data from professional GPS devices.

2. the coordinate system used by the International Map.

3. Google maps outside China and osm maps

Mars coordinate (GCJ-02)

  1. The standard adopted in China is called the coordinate system of the China Communications Administration. The data can be obtained from the mobile devices of China Bank.

2. All kinds of maps published in China use at least GCJ-02 to encrypt the geographic location offset

  3. AMAP, Map of heaven and earth, search for maps, etc.

Baidu axis (BD-09)

1. Coordinates Used by Baidu map.

2. Baidu coordinates are re-encrypted on the basis of GCJ-02

  3. Baidu Map

Ii. Conversion between major Coordinate Systems

General entity

1 /// <summary> 2 /// longitude and latitude 3 /// </summary> 4 public class StationGps 5 {6 /// <summary> 7 // longitude 8 /// </summary> 9 public double longpolling {get; set;} 10 // <summary> 11 // latitude 12 // </summary> 13 public double latitude {get; set;} 14}

 

1. Convert the coordinates of Mars to Baidu
 1        private static double x_pi = 3.14159265358979324 * 3000.0 / 180.0; 2  3         public static StationGps HxToBd(double lon, double lat) 4         { 5             var result = new StationGps(); 6             double x = lon, y = lat; 7             var z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi); 8             var theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi); 9             result.longitude = z * Math.Cos(theta) + 0.0065;10             result.latitude = z * Math.Sin(theta) + 0.006;11             return result;12         }
View Code2, Baidu to Mars coordinates
 1         private static double x_pi = 3.14159265358979324 * 3000.0 / 180.0; 2            3         public static StationGps BdToHx(double lon, double lat) 4         { 5             var result = new StationGps(); 6             double x = lon - 0.0065, y = lat - 0.006; 7             var z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi); 8             var theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi); 9             result.longitude = z * Math.Cos(theta);10             result.latitude = z * Math.Sin(theta);11             return result;12         }
View Code3: Earth coordinates of the world to Mars coordinates
 1         private static double pi = 3.14159265358979324; 2         private static double a = 6378245.0; 3         private static double ee = 0.00669342162296594323;  4  5         public static StationGps WgsToHx(double lon, double lat) 6         { 7             var result = new StationGps(); 8             double dLat = TransformLat(lat - 35.0, lon - 105.0); 9             double dLon = TransformLon(lat - 35.0, lon - 105.0);10             double radLat = lat / 180.0 * pi;11             double magic = Math.Sin(radLat);12             magic = 1 - ee * magic * magic;13             var sqrtMagic = Math.Sqrt(magic);14             dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);15             dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);16             result.latitude = lat + dLat;17             result.longitude = lon + dLon;18             return result;19         }20 21         private static double TransformLat(double lon, double lat)22         {23             var ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon + 0.2 * Math.Sqrt(Math.Abs(lat));24             ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;25             ret += (20.0 * Math.Sin(lon * pi) + 40.0 * Math.Sin(lon / 3.0 * pi)) * 2.0 / 3.0;26             ret += (160.0 * Math.Sin(lon / 12.0 * pi) + 320 * Math.Sin(lon * pi / 30.0)) * 2.0 / 3.0;27             return ret;28         }29         private static double TransformLon(double lon, double lat)30         {31             var ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * Math.Sqrt(Math.Abs(lat));32             ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;33             ret += (20.0 * Math.Sin(lat * pi) + 40.0 * Math.Sin(lat / 3.0 * pi)) * 2.0 / 3.0;34             ret += (150.0 * Math.Sin(lat / 12.0 * pi) + 300.0 * Math.Sin(lat / 30.0 * pi)) * 2.0 / 3.0;35             return ret;36         }
View Code4: Convert World Earth coordinates to Baidu coordinates
 1         private static double pi = 3.14159265358979324; 2         private static double a = 6378245.0; 3         private static double ee = 0.00669342162296594323; 4         private static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;  5  6         public static StationGps WgsToBd(double lon, double lat) 7         { 8             var hx = WgsToHx(lon, lat); 9             var bd = HxToBd(hx.longitude, hx.latitude);10             return bd;11         }12 13         public static StationGps HxToBd(double lon, double lat)14         {15             var result = new StationGps();16             double x = lon, y = lat;17             var z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi);18             var theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi);19             result.longitude = z * Math.Cos(theta) + 0.0065;20             result.latitude = z * Math.Sin(theta) + 0.006;21             return result;22         } 23 24         public static StationGps WgsToHx(double lon, double lat)25         {26             var result = new StationGps();27             double dLat = TransformLat(lat - 35.0, lon - 105.0);28             double dLon = TransformLon(lat - 35.0, lon - 105.0);29             double radLat = lat / 180.0 * pi;30             double magic = Math.Sin(radLat);31             magic = 1 - ee * magic * magic;32             var sqrtMagic = Math.Sqrt(magic);33             dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);34             dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);35             result.latitude = lat + dLat;36             result.longitude = lon + dLon;37             return result;38         }39 40         private static double TransformLat(double lon, double lat)41         {42             var ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon + 0.2 * Math.Sqrt(Math.Abs(lat));43             ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;44             ret += (20.0 * Math.Sin(lon * pi) + 40.0 * Math.Sin(lon / 3.0 * pi)) * 2.0 / 3.0;45             ret += (160.0 * Math.Sin(lon / 12.0 * pi) + 320 * Math.Sin(lon * pi / 30.0)) * 2.0 / 3.0;46             return ret;47         }48 49         private static double TransformLon(double lon, double lat)50         {51             var ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * Math.Sqrt(Math.Abs(lat));52             ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;53             ret += (20.0 * Math.Sin(lat * pi) + 40.0 * Math.Sin(lat / 3.0 * pi)) * 2.0 / 3.0;54             ret += (150.0 * Math.Sin(lat / 12.0 * pi) + 300.0 * Math.Sin(lat / 30.0 * pi)) * 2.0 / 3.0;55             return ret;56         } 
View Code

 

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.