python-mutual conversion of latitude and longitude coordinates and plane projection coordinates

Maesel modeling needs to use a plane coordinate system to make a time series-based range of motion model, so it is necessary to convert the latitude and longitude coordinate system to the XY coordinate system. At the same time, the conversion of the coordinate system is still often used in the path planning of the robot, so record it.

Latitude and Longitude Coordinate System and Plane Projection Coordinate System

Geographical Coordinate System / Geodetic Coordinate System

The geographic coordinate system, also known as the geodetic coordinate system, is expressed by latitude and longitude.

  • The coordinates of the reference ellipsoid as the datum plane in geodetic surveying. The location of the ground point P is represented by the geodetic longitude L, the geodetic latitude B, and the geodetic height H. When the point is on the reference ellipsoid, it is only represented by the geodetic longitude and the geodetic latitude. The longitude of the earth is the angle between the meridian of the earth passing through the point and the meridian of the starting earth, the latitude of the earth is the angle between the normal of the point passing through the point and the equatorial plane, and the height of the earth is the angle of the ground point along the normal to the reference ellipsoid. the distance.

Plane Projection Coordinate System

People are more accustomed to using a plane coordinate system, which is represented by xy.

  • A certain method is needed to convert the coordinates of the surface of the sphere into plane coordinates. This method is called projection . The projection is in the XYZ plane. Sometimes it is not convenient to use the geographic coordinate system, and the projection method is not the only one. It is for one purpose to ensure that the local coordinates are the most accurate. So there are many projection methods, such as Gaussian projection, Mercator projection and so on .

Both geodetic coordinates and geographic coordinates are spherical , and projected coordinates are plane.

Mercator projection

If (B,L)the new coordinates obtained by Mercator projection (below) are points (X,Y),
where B0is the standard latitude, L0is the standard longitude, eis the first eccentricity, and e ’is the second eccentricity. According to the Mercator projection method, we can realize the coordinate system The mutual transformation.
Mercator projection

Variable and constant definition

The semi-major axis aof the ellipse, the semi-minor axis of the ellipse b:
Insert picture description hereInsert picture description here

(1) Mercator projection correct calculation formula

The plane projection coordinates are(B,L) calculated from the latitude and longitude coordinates(X,Y) :
Insert picture description here

(2) Inverse solution formula of Mercator projection

The latitude and longitude coordinates are(X,Y) calculated from the plane projection coordinates(B,L) . You can use the Newton iteration method to solve, that is, if q is known to find B, the method is as follows:
Insert picture description here

Python code implementation

(1) Mercator projection correct calculation formula

There are still minor issues with the code, and I need your help to correct me.

from math import *

def get_coordinate(latitude,longitude):
    B = latitude
    L = longitude
    q = log( tan(pi/4 + B/2)*(1-exp(1)*sin(B)) / (1+exp(1)*sin(B))**exp(1/2) )
    x = K*q
    y = K*(L-L0)
    return (x, y)

if __name__ == '__main__':
    latitude = 34
    longitude = -167
    a = 6378137.0000 # 单位为m
    b = 6356752.3142
    B0 = 0; L0 = 0;
    e1 = sqrt(pow(a,2) - pow(b,2)) / a
    e2 = sqrt(pow(a,2) - pow(b,2)) / b
    K = a* cos(B0) / sqrt(1-pow(exp(2), 2)*pow(sin(B0), 2))
    
    data = get_coordinate(latitude,longitude)
    print(data)

Run example:
Insert picture description here

(2) Inverse solution formula of Mercator projection

The formula already exists and can be reproduced by itself.

Reference papers:

Guess you like

Origin blog.csdn.net/qq_45779334/article/details/113772733