/** ****************************************************************************** * @file : task_alog_c.cpp * @author : wyj * @brief : C语言语法测试 * @attention : None * @date : 2025/5/9 ****************************************************************************** */ #ifdef __cplusplus extern "C" { #endif #include "geography/studio_proj_c.h" #include "geometry/studio_geo_algo_c.h" #ifdef __cplusplus } #endif #include #include #include "geometry/studio_geo_utils.h" void studio_line_to_c_line(const studio_line &line, studio_line_c *c_line) { for (size_t i = 0; i < line.size(); ++i) { studio_point_c p = studio_point_init(line[i].x, line[i].y); studio_line_c_add_point(c_line, p); } } void c_line_to_studio_line(const studio_line_c *c_line, studio_line &line) { for (size_t i = 0; i < c_line->size; ++i) { const studio_point_c *p = studio_line_c_get_point(c_line, i); line.push_back(studio_point(p->x, p->y)); } } // ///////////////////// 移除离群点 //////////////////////////////// // int main() // { // printf("\n\n===================== %s =====================\n\n", __FILE__); // silly::geo::utils::init_gdal_env(); // std::string path; // #ifdef IS_WINDOWS // path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples.geojson"; // #else // path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples.geojson"; // #endif // // std::cout << "path: " << path << std::endl; // std::vector res_collections; // std::vector collections; // silly::geo::utils::read_geo_coll(path, collections); // // for (auto &coll: collections) // { // studio_line_c line_c = studio_line_c_init(); // studio_line_to_c_line(coll.m_line, &line_c); // std::cout << "原始数据量:" << coll.m_line.size() << std::endl; // // studio_line_c outliers_line = studio_line_c_init(); // remove_outliers_c(&line_c, 1, &outliers_line); // // studio_line simplified_line; // c_line_to_studio_line(&outliers_line, simplified_line); // std::cout << "简化后数据量:" << simplified_line.size() << std::endl; // // studio_geo_coll temp; // temp.m_type = enum_geometry_type::egtLineString; // temp.m_line = simplified_line; // res_collections.push_back(temp); // // studio_line_c_destroy(&line_c); // studio_line_c_destroy(&outliers_line); // // break; // } // // // std::string output_path; // #ifdef IS_WINDOWS // output_path = "D:/5_file/2_readfile/geojson/multi_point/remove_outliers.geojson"; // #else // output_path = "/home/wyj/myself/2_data/2_geojson/multi_point/remove_outliers.geojson"; // #endif // silly::geo::utils::write_geo_coll(output_path, res_collections); // silly::geo::utils::destroy_gdal_env(); // return 0; // } // //////////////////// 路径压缩算法测试 ////////////////////// int main() { printf("\n\n===================== %s =====================\n\n", __FILE__); silly::geo::utils::init_gdal_env(); std::string path; #ifdef IS_WINDOWS path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples.geojson"; #else path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples.geojson"; #endif std::cout << "path: " << path << std::endl; std::vector res_collections; std::vector collections; silly::geo::utils::read_geo_coll(path, collections); for (auto &coll: collections) { studio_line_c line_c = studio_line_c_init(); studio_line_c vac_line_c = studio_line_c_init(); studio_line_to_c_line(coll.m_line, &line_c); // 简化线段,目标点数为28个 int max_points = 28; double epsilon = 1.0; bool res = line_vacuate_gcs_c(&line_c, max_points, epsilon, &vac_line_c); if (!res) { std::cout << "Failed to simplify line." << std::endl; return 1; } studio_line simplified_line; c_line_to_studio_line(&vac_line_c, simplified_line); studio_geo_coll temp; temp.m_type = enum_geometry_type::egtLineString; temp.m_line = simplified_line; res_collections.push_back(temp); studio_line_c_destroy(&line_c); studio_line_c_destroy(&vac_line_c); break; } std::string output_path; #ifdef IS_WINDOWS output_path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples_res_1.geojson"; #else output_path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples_res_2_c.geojson"; #endif silly::geo::utils::write_geo_coll(output_path, res_collections); silly::geo::utils::destroy_gdal_env(); return 0; } // int main() // { // printf("\n\n===================== %s =====================\n\n", __FILE__); // silly::geo::utils::init_gdal_env(); // std::string path; // #ifdef IS_WINDOWS // path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples.geojson"; // #else // path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples.geojson"; // #endif // // std::cout << "path: " << path << std::endl; // std::vector res_collections; // std::vector collections; // silly::geo::utils::read_geo_coll(path, collections); // for (auto &coll : collections) // { // // ------------- 转换为高斯投影 ------------- // studio_line gauss_line; // double central = static_cast(coll.m_line[0].x / 3) * 3; // for (auto &point : coll.m_line) // { // double gx = 0.0; // double gy = 0.0; // lonlat_to_gauss(central, point.x, point.y, &gx, &gy); // gauss_line.push_back(studio_point(gx, gy)); // } // studio_line_c gauss_line_c = studio_line_c_init(); // studio_line_c vac_gauss_line_c = studio_line_c_init(); // studio_line_to_c_line(gauss_line, &gauss_line_c); // // // 简化线段,目标点数为28个 // int max_points = 28; // double epsilon = 1.0; // // bool res = line_vacuate_c(&gauss_line_c, max_points, epsilon, &vac_gauss_line_c); // if (!res) // { // std::cout << "Failed to simplify line." << std::endl; // return 1; // } // // // 高斯投影在转回经纬度 // studio_line simplified_line; // for (int i = 0; i < vac_gauss_line_c.size; i++) // { // double lon = 0.0; // double lat = 0.0; // const studio_point_c *p = studio_line_c_get_point(&vac_gauss_line_c, i); // gauss_to_lonlat(central, p->x, p->y, &lon, &lat); // simplified_line.push_back(studio_point(lon, lat)); // } // // studio_geo_coll temp; // temp.m_type = enum_geometry_type::egtLineString; // temp.m_line = simplified_line; // res_collections.push_back(temp); // // studio_line_c_destroy(&gauss_line_c); // studio_line_c_destroy(&vac_gauss_line_c); // // break; // } // std::string output_path; // #ifdef IS_WINDOWS // output_path = "D:/5_file/2_readfile/geojson/multi_point/fitting_examples_res_1.geojson"; // #else // output_path = "/home/wyj/myself/2_data/2_geojson/multi_point/fitting_examples_res_1_c.geojson"; // #endif // silly::geo::utils::write_geo_coll(output_path, res_collections); // // silly::geo::utils::destroy_gdal_env(); // // return 0; // }