|
@@ -26,8 +26,8 @@ extern "C"
|
|
|
|
|
|
void studio_line_to_c_line(const studio_line &line, studio_line_c *c_line)
|
|
|
{
|
|
|
-// c_line->size = line.size();
|
|
|
- c_line->data = (studio_point_c *)malloc(line.size() * sizeof(studio_point_c));
|
|
|
+ // c_line->size = line.size();
|
|
|
+ c_line->data = (studio_point_c *) malloc(line.size() * sizeof(studio_point_c));
|
|
|
for (size_t i = 0; i < line.size(); ++i)
|
|
|
{
|
|
|
studio_point_c p = studio_point_init(line[i].x, line[i].y);
|
|
@@ -44,6 +44,7 @@ void c_line_to_studio_line(const studio_line_c *c_line, studio_line &line)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+///////////////////// 移除离群点 ////////////////////////////////
|
|
|
int main()
|
|
|
{
|
|
|
printf("\n\n===================== %s =====================\n\n", __FILE__);
|
|
@@ -59,63 +60,117 @@ int main()
|
|
|
std::vector<studio_geo_coll> res_collections;
|
|
|
std::vector<studio_geo_coll> collections;
|
|
|
silly::geo::utils::read_geo_coll(path, collections);
|
|
|
- for (auto &coll : collections)
|
|
|
+
|
|
|
+ for (auto &coll: collections)
|
|
|
{
|
|
|
- // ------------- 转换为高斯投影 -------------
|
|
|
- studio_line gauss_line;
|
|
|
- double central = static_cast<int>(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_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;
|
|
|
- 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));
|
|
|
- }
|
|
|
+ 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(&gauss_line_c);
|
|
|
- studio_line_c_destroy(&vac_gauss_line_c);
|
|
|
+ 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/fitting_examples_res_1.geojson";
|
|
|
+ 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/fitting_examples_res_1_c.geojson";
|
|
|
+ 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<studio_geo_coll> res_collections;
|
|
|
+// std::vector<studio_geo_coll> collections;
|
|
|
+// silly::geo::utils::read_geo_coll(path, collections);
|
|
|
+// for (auto &coll : collections)
|
|
|
+// {
|
|
|
+// // ------------- 转换为高斯投影 -------------
|
|
|
+// studio_line gauss_line;
|
|
|
+// double central = static_cast<int>(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;
|
|
|
+// }
|