china_shift.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # load dynamic C library for map shift
  2. from ctypes import *
  3. shift = cdll.LoadLibrary('./china_shift.so')
  4. class Location(Structure):
  5. _fields_ = [
  6. ('lon', c_double),
  7. ('lat', c_double)]
  8. shift.transformFromWGSToGCJ.argtypes = [Location]
  9. shift.transformFromWGSToGCJ.restype = Location
  10. shift.transformFromGCJToWGS.argtypes = [Location]
  11. shift.transformFromGCJToWGS.restype = Location
  12. shift.bd_encrypt.argtypes = [Location]
  13. shift.bd_encrypt.restype = Location
  14. shift.bd_decrypt.argtypes = [Location]
  15. shift.bd_decrypt.restype = Location
  16. def test_china_shift():
  17. # Location gps = { 119.465265, 29.1934702};
  18. # 地球WGS-84 转 火星GCJ-02 转 百度BD-09
  19. loc = Location(lon = 119.465265, lat = 29.1934702)
  20. print("地球WGS-84:",loc.lat, loc.lon)
  21. loc = shift.transformFromWGSToGCJ(loc)
  22. print("火星GCJ-02:",loc.lat, loc.lon)
  23. loc = shift.bd_encrypt(loc)
  24. print("百度 BD-09:",loc.lat, loc.lon)
  25. # 百度BD-09 转 火星GCJ-02 转 地球WGS-84
  26. loc = Location(lon = 119.476936, lat = 29.196518 )
  27. print("百度 BD-09:",loc.lat, loc.lon)
  28. loc = shift.bd_decrypt(loc)
  29. print("火星GCJ-02:",loc.lat, loc.lon)
  30. loc = shift.transformFromGCJToWGS(loc)
  31. print("地球WGS-84:",loc.lat, loc.lon)
  32. if __name__ == '__main__':
  33. test_china_shift()