蘭雅sRGB 个人笔记 https://262235.xyz
提供编程和电脑应用视频教程,工具和源代码
C, C++, Python Programming, Source Code, Video

旧Hexo博客 | Github | IP定位WebAPI | Docker Hub
编程中文文档 | 网盘分享 | 中文Linux命令

Python 调用 C库 测试GPS坐标互转: 地球WGS-84 火星GCJ-02 百度BD-09

WGS2GCJ.png

地球WGS-84 转 火星GCJ-02 转 百度BD-09

地球WGS-84: 29.1934702 119.465265
火星GCJ-02: 29.1908196 119.470341
百度 BD-09: 29.1965172 119.476936

百度BD-09 转 火星GCJ-02 转 地球WGS-84

百度 BD-09: 29.196518 119.476936
火星GCJ-02: 29.1908195 119.470342
地球WGS-84: 29.1934702 119.465265

china_shift.py 测试源码

# load dynamic C library for map shift
from ctypes import *
shift = cdll.LoadLibrary('./china_shift.so')

class Location(Structure):
    _fields_ = [
        ('lon', c_double),
        ('lat', c_double)]

shift.transformFromWGSToGCJ.argtypes = [Location]
shift.transformFromWGSToGCJ.restype = Location
shift.transformFromGCJToWGS.argtypes = [Location]
shift.transformFromGCJToWGS.restype = Location

shift.bd_encrypt.argtypes = [Location]
shift.bd_encrypt.restype = Location
shift.bd_decrypt.argtypes = [Location]
shift.bd_decrypt.restype = Location
      
# Location gps = { 119.465265, 29.1934702}; 
# 地球WGS-84 转 火星GCJ-02 转 百度BD-09

loc = Location(lon = 119.465265, lat = 29.1934702)
print("地球WGS-84:",loc.lat, loc.lon)

loc = shift.transformFromWGSToGCJ(loc)
print("火星GCJ-02:",loc.lat, loc.lon)

loc = shift.bd_encrypt(loc)
print("百度 BD-09:",loc.lat, loc.lon)

# 百度BD-09 转 火星GCJ-02 转 地球WGS-84
loc = Location(lon = 119.476936, lat = 29.196518 )
print("百度 BD-09:",loc.lat, loc.lon)

loc = shift.bd_decrypt(loc)
print("火星GCJ-02:",loc.lat, loc.lon)

loc = shift.transformFromGCJToWGS(loc)
print("地球WGS-84:",loc.lat, loc.lon)

Gcc 编译 china_shift.so 转换坐标库命令 参考链接

gcc -shared -fPIC -o china_shift.so china_shift.c
本原创文章自由转载,转载请注明本博来源及网址 | 当前页面:兰雅sRGB个人笔记 » Python 调用 C库 测试GPS坐标互转: 地球WGS-84 火星GCJ-02 百度BD-09