36int main(
int argc,
char* argv[])
39 "Remove points from geometry that are not used in any polyline nor "
40 "surface. Attention: Names of points are not handled correctly in "
42 "OpenGeoSys-6 software, version " +
45 "Copyright (c) 2012-2026, OpenGeoSys Community "
46 "(http://www.opengeosys.org)",
49 TCLAP::ValueArg<std::string> geo_output_arg(
50 "o",
"output",
"Output (.gml) geometry",
true,
"",
"OUTPUT_FILE");
51 cmd.add(geo_output_arg);
52 TCLAP::ValueArg<std::string> geo_input_arg(
53 "i",
"input",
"Input (.gml) geometry",
true,
"conceptual model",
55 cmd.add(geo_input_arg);
57 cmd.add(log_level_arg);
58 cmd.parse(argc, argv);
67 if (!xml.
readFile(geo_input_arg.getValue()))
69 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
73 catch (std::runtime_error
const& err)
75 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
76 ERR(
"{:s}", err.what());
81 auto* points =
const_cast<std::vector<GeoLib::Point*>*
>(
87 auto used_points = std::vector<bool>(points->size(),
false);
89 auto mark = [&](
auto const*
const object)
94 ranges::for_each(*polylines, mark);
98 ranges::for_each(*surfaces, mark);
101 auto const number_of_used_points =
static_cast<std::size_t
>(
102 std::count(used_points.begin(), used_points.end(),
true));
103 if (number_of_used_points == 0)
106 "Geometry consists of points only. A new geometry file won't "
111 "{} points in this geometry file are not used in any polyline or "
113 points->size() - number_of_used_points);
117 auto reset = [&mapping](
auto* object)
123 ranges::for_each(*polylines, reset);
128 ranges::for_each(*surfaces, reset);
131 std::stringstream unused_points_info;
132 unused_points_info << std::fixed;
136 ranges::views::zip(*points, used_points) |
137 ranges::views::filter([](
auto&& pair) {
return !pair.second; }) |
140 unused_points_info << point->getID() <<
" " << *point <<
'\n';
145 std::erase(*points,
nullptr);
146 if (!unused_points_info.str().empty())
148 INFO(
"Removed the following points:\n{}", unused_points_info.str());
151 WARN(
"Names of points are not handled correctly in every case.");
155 geo_output_arg.getValue());