task_alog_c.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. ******************************************************************************
  3. * @file : task_alog_c.cpp
  4. * @author : wyj
  5. * @brief : C语言语法测试
  6. * @attention : None
  7. * @date : 2025/5/9
  8. ******************************************************************************
  9. */
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include "geography/studio_proj_c.h"
  14. #ifdef __cplusplus
  15. }
  16. #endif
  17. #include <stdio.h>
  18. #include <stdio.h>
  19. #include "geometry/studio_geo_utils.h"
  20. #include "geometry/studio_geo_algo.h"
  21. int main() {
  22. printf("\n\n===================== %s =====================\n\n", __FILE__);
  23. silly::geo::utils::init_gdal_env();
  24. std::string path;
  25. #ifdef IS_WINDOWS
  26. path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples.geojson";
  27. #else
  28. path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples.geojson";
  29. #endif
  30. std::cout << "path: " << path << std::endl;
  31. std::vector<studio_geo_coll> res_collections;
  32. std::vector<studio_geo_coll> collections;
  33. silly::geo::utils::read_geo_coll(path, collections);
  34. for (auto &coll: collections) {
  35. // ------------- 转换为高斯投影 -------------
  36. studio_line gauss_line;
  37. double central = static_cast<int>(coll.m_line[0].x / 3) * 3;
  38. for (auto &point: coll.m_line) {
  39. double gx = 0.0;
  40. double gy = 0.0;
  41. lonlat_to_gauss(central, point.x, point.y, &gx, &gy);
  42. gauss_line.push_back(studio_point(gx, gy));
  43. }
  44. // 简化线段,目标点数为28个
  45. int max_points = 28;
  46. double epsilon = 0.001;
  47. // studio_line gs_simplified_line = simplify_line_2(gauss_line, max_points);
  48. studio_line gs_simplified_line;
  49. bool res = geo_vacuate::vacuate(gauss_line, max_points, epsilon, gs_simplified_line);
  50. if (!res) {
  51. std::cout << "Failed to simplify line." << std::endl;
  52. return 1;
  53. }
  54. studio_line simplified_line;
  55. // 高斯投影在转回经纬度
  56. for (auto &point: gs_simplified_line) {
  57. double lon = 0.0;
  58. double lat = 0.0;
  59. gauss_to_lonlat(central, point.x, point.y, &lon, &lat);
  60. simplified_line.push_back(studio_point(lon, lat));
  61. }
  62. studio_geo_coll temp;
  63. temp.m_type = enum_geometry_type::egtLineString;
  64. temp.m_line = simplified_line;
  65. res_collections.push_back(temp);
  66. break;
  67. }
  68. std::string output_path;
  69. #ifdef IS_WINDOWS
  70. output_path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples_res_1.geojson";
  71. #else
  72. output_path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples_res_1_c.geojson";
  73. #endif
  74. silly::geo::utils::write_geo_coll(output_path, res_collections);
  75. silly::geo::utils::destroy_gdal_env();
  76. return 0;
  77. }