Introduction and Common coordinate conversion (with code)

Original Address: http://www.mapboxx.cn/article/geography/

basic concepts ## coordinate system
coordinates into geographic coordinates and projected coordinate system, the following is an explanation of these two coordinate systems:

* geographic coordinates Department: spherical coordinates. The reference plane is ellipsoidal coordinate units: latitude and longitude

* projected coordinate system: the coordinate plane. Be a horizontal reference plane, the coordinate units: meters, kilometers, etc.

geotransform projection coordinates to be understood as the process of projection (projection: the irregular surface is converted to the earth plane)

## of the type common coordinate system and explanations

* WGS84: geographic coordinate system, Google Earth and Google Map use outside of China, in addition, essentially, all the positioning device spatial location use this coordinate system, such as the phone's GPS system

* GCJ-02: projected coordinate system, that is, we usually say Mars coordinate system, Google Map China, Germany and Tencent seems that the use of high, this is the Chinese themselves by encrypting the WGS84 basis, the purpose is obvious.

* BD09: projected coordinate system, using Baidu map, made in the secondary encryption GCJ-02 basis.

Domestic API coordinate system compares

| API | coordinates |
| ---- | ---- |
| Baidu Maps API | Baidu coordinate |
| Tencent Soso Maps API | Mars coordinate |
| Sohu Sogou Map API | Sogou coordinate |
Ali cloud map API | Mars coordinate |
| Figure it MapBar Maps API | map it coordinates |
| MapABC high moral map API | Mars coordinate |
| Lingtu 51ditu Map API | Mars coordinates |


WGS84 UTM projection coordinates generally use, zoning 6 degrees, UTM projection 11 across the country, with a number in 43-53

| with numbers | Central longitude | longitude range |
| ---- | ---- | ---- |
| 43 is | 75E | 72E-78E |
| 44 is | 81E | 78E-84E |
| 45 | 87E | 84E-90E |
| 46 is | 93E | 90E-96E |
| 47 | 99E | 96E-102E |
| 48 | 105E | 102E-108E |
| 49 | 111E | 108E-114E |
| 50 | 117E | 114E-120E |
| 51 is | 123E | 120E- 126E |
| 52 | 129E | 126E-132E |
| 53 | 135E | 132E-138E |

## coordinate correction

to Mars coordinate system, Baidu coordinate system into coordinates WGS1984 called coordinate correction

to offset coordinates: Mars coordinate system, Baidu coordinate system;

Mars coordinate system, Baidu is to coordinate national security, the relative sector WGS1984 offset, generated encryption

Here are the tools coordinate conversion online, and upload corresponding EXCEL files can be converted to support BD09, GCJ20, WGS84 coordinate system of the three kinds of conversion, address: [http://www.mapboxx.cn/tool/coord_view /](http://www.mapboxx.cn/tool/coord_view/)

Of course, if the code is required, you can look down.

## coordinates correction, overall understanding of the coordinate system

! [RUNOOB icon] (http://www.mapboxx.cn/static/blog/img/article/coodirate.png)


## attached
Website: HTTP: // the WWW. mapboxx.cn an on-line, there are many online tools and map-related knowledge sharing tools including people crawling traffic data, POI data crawling, and map data visualization, coordinate conversion, welcomed the visit.

## common map coordinate system transformation code (python version)
supports BD09 coordinate system, GCJ20 coordinates, WGS84 coordinate system conversion.
`` `
! # / Usr / bin / the env to python3
# - * - Coding: UTF-. 8 - * -

__author =" Brady_Hu "

Import Math

x_pi = 3.14159265358979324 * 3000.0 / 180.0
PI = [pi] 3.1415926535897932384626 #
A # = 6,378,245.0 semiaxis
ee = 0.00669342162296594323 # flat rate


DEF gcj02_to_bd09 (lng, LAT):
    "" "
    Mars coordinate system (GCJ-02) turn Baidu coordinate system (BD-09)
    Google, High German -> Baidu
    : param lng: Mars coordinates Longitude
    : param lat: Mars Location latitude
    : return:
    "" "
    Z = Math.sqrt (LNG LNG * + * LAT LAT) + 0.00002 * Math.sin (LAT * x_pi)
    Theta = Math.atan2 (LAT, LNG) + 0.000003 * Math.cos (LNG * x_pi)
    bd_lng Math.cos = Z * (Theta) + 0.0065
    bd_lat Math.sin = Z * (Theta) + 0.006
    return [bd_lng, bd_lat]


DEF bd09_to_gcj02 (bd_lon, bd_lat):
    "" "
    Baidu coordinate system (BD-09) turn Mars coordinate system (GCJ-02)
    Baidu -> Google, high German
    : param bd_lat: Baidu coordinates latitude
    : bd_lon param: Baidu longitude coordinates
    : return: the converted coordinate list in the form of
    "" "
    X = bd_lon - 0.0065
    Y = bd_lat - 0.006
    Z = Math.sqrt (Y * X * X + Y) - Math.sin 0.00002 * (Y * x_pi)
    Theta = Math .atan2 (Y, X) - 0.000003 * Math.cos (X * x_pi)
    gg_lng Math.cos = Z * (Theta)
    gg_lat Math.sin = Z * (Theta)
    return [gg_lng, gg_lat]


DEF wgs84_to_gcj02 (LNG, LAT ):
    "" "
    WGS84 turn GCJ02 (Mars coordinates)
    : param lng: WGS84 coordinates longitude
    : param lat: latitude WGS84 coordinate system
    : return:
    " ""
    iF out_of_china (lng, LAT): # determine whether at home
        LNG return, LAT
    DLAT = _transformlat (LNG - 105.0, LAT - 35.0)
    dlng = _transformlng (LNG - 105.0,years - 35.0)
    LAT = radlat / 180.0 * PI
    Magic = Math.sin (radlat)
    Magic =. 1 - EE * * Magic Magic
    sqrtmagic = Math.sqrt (Magic)
    DLAT = (DLAT * 180.0) / ((A * (. 1 - EE)) / (Magic sqrtmagic *) * PI)
    dlng = (dlng * 180.0) / (A / sqrtmagic * Math.cos (radlat) * PI)
    mglat = LAT + DLAT
    mglng = + dlng LNG
    return [mglng, mglat]


DEF gcj02_to_wgs84 ( lng, LAT):
    "" "
    GCJ02 (Mars coordinate system) turn GPS84
    : param lng: longitude Mars coordinates
    : param lat: Mars coordinates latitude
    : return:
    " ""
    IF out_of_china (lng, LAT):
        return lng, LAT
    DLAT = _transformlat (LNG - 105.0, LAT - 35.0)
    dlng = _transformlng(lng - 105.0, lat - 35.0)
    radlat = lat / 180.0 * pi
    magic = math.sin(radlat)
    magic = 1 - ee * magic * magic
    sqrtmagic = math.sqrt(magic)
    dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
    dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
    mglat = lat + dlat
    mglng = lng + dlng
    return [lng * 2 - mglng, lat * 2 - mglat]


def bd09_to_wgs84(bd_lon, bd_lat):
    lon, lat = bd09_to_gcj02(bd_lon, bd_lat)
    return gcj02_to_wgs84(lon, lat)


def wgs84_to_bd09(lon, lat):
    lon, lat = wgs84_to_gcj02(lon, lat)
    return gcj02_to_bd09(lon, lat)


def _transformlat (lng, lat):
    ret = -100.0 + 2.0 + 3.0 * u * + 0.2 * lat lat lat + * \
          0.1 * u * lat + 0.2 * Math.sqrt (math.fabs (LNG))
    ret + = (20.0 * Math.sin (6.0 * i * pi) + 20.0 *
            Math.sin (2.0 * i * pi)) * 2.0 / 3.0
    ret + = (20.0 * Math.sin (lat * pi) + 40.0 *
            math. sin (lat / 3.0 * pi)) * 2.0 / 3.0
    ret + = (160.0 * Math.sin (lat / 12.0 * pi) + 320 *
            Math.sin (lat * pi / 30.0)) * 2.0 / 3.0
    return ret


def _transformlng (lng, lat):
    ret = 300.0 + u + 2.0 + 0.1 * lAT * lNG * lNG + \
          0.1 * u * lat + 0.1 * Math.sqrt (math.fabs (lNG))
    ret + = (20.0 * math .Who (6.0 * i * pi) + 20.0 *
            math.sin(2.0 * lng * pi)) * 2.0 / 3.0
    ret += (20.0 * math.sin(lng * pi) + 40.0 *
            math.sin(lng / 3.0 * pi)) * 2.0 / 3.0
    ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 *
            math.sin(lng / 30.0 * pi)) * 2.0 / 3.0
    return ret


def out_of_china(lng, lat):
    """
    判断是否在国内,不在国内不做偏移
    :param lng:
    :param lat:
    :return:
    """
    return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55)

if __name__ == '__main__':
    lng = 128.543
    lat = 37.065
    result1 = gcj02_to_bd09(lng, lat)
    result2 = bd09_to_gcj02(lng,years)
    result3 = wgs84_to_gcj02(lng, lat)
    result4 = gcj02_to_wgs84(lng, lat)
    result5 = bd09_to_wgs84(lng, lat)
    result6 = wgs84_to_bd09(lng, lat)

    print(result1, result2, result3, result4, result5, result6)
```


















 

Guess you like

Origin www.cnblogs.com/liujiao/p/11442845.html