You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

web_mercator.cpp 767 B

2 years ago
1234567891011121314151617181920212223242526272829303132
  1. #include "geo/private/util/angle_util.h"
  2. #include "geo/private/coord/web_mercator.h"
  3. namespace ns
  4. {
  5. namespace geo
  6. {
  7. static double g_delta = 20037508.34 / 180;
  8. static double g_1_delta = 180.0 / 20037508.34;
  9. static double g_PI_180 = c_pi() / 180.0;
  10. static double g_PI_360 = c_pi() / 360.0;
  11. PointD lonLat2WebMercator(const PointD& lonLat)
  12. {
  13. double x = lonLat.x * g_delta;
  14. double y = log(tan((90 + lonLat.y) * g_PI_360)) / g_PI_180;
  15. y = y * g_delta;
  16. return {x, y};
  17. }
  18. // Web墨卡托转经纬度
  19. PointD webMercator2LonLat(const PointD& mercator)
  20. {
  21. double x = mercator.x * g_1_delta;
  22. double y = mercator.y * g_1_delta;
  23. y = 180 * c_1_pi() * (2 * atan(exp(y * g_PI_180)) - c_pi_2());
  24. return {x, y};
  25. }
  26. } // namespace geo
  27. } // namespace ns