43int main(
int argc,
char* argv[])
46 "Remove points from geometry that are not used in any polyline nor "
47 "surface. Attention: Names of points are not handled correctly in "
49 "OpenGeoSys-6 software, version " +
52 "Copyright (c) 2012-2025, OpenGeoSys Community "
53 "(http://www.opengeosys.org)",
56 TCLAP::ValueArg<std::string> geo_output_arg(
57 "o",
"output",
"Output (.gml) geometry",
true,
"",
"OUTPUT_FILE");
58 cmd.add(geo_output_arg);
59 TCLAP::ValueArg<std::string> geo_input_arg(
60 "i",
"input",
"Input (.gml) geometry",
true,
"conceptual model",
62 cmd.add(geo_input_arg);
64 cmd.add(log_level_arg);
65 cmd.parse(argc, argv);
74 if (!xml.readFile(geo_input_arg.getValue()))
76 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
80 catch (std::runtime_error
const& err)
82 ERR(
"Failed to read file `{:s}'.", geo_input_arg.getValue());
83 ERR(
"{:s}", err.what());
88 auto* points =
const_cast<std::vector<GeoLib::Point*>*
>(
94 auto used_points = std::vector<bool>(points->size(),
false);
96 auto mark = [&](
auto const*
const object)
101 ranges::for_each(*polylines, mark);
105 ranges::for_each(*surfaces, mark);
108 auto const number_of_used_points =
static_cast<std::size_t
>(
109 std::count(used_points.begin(), used_points.end(),
true));
110 if (number_of_used_points == 0)
113 "Geometry consists of points only. A new geometry file won't "
118 "{} points in this geometry file are not used in any polyline or "
120 points->size() - number_of_used_points);
124 auto reset = [&mapping](
auto* object)
130 ranges::for_each(*polylines, reset);
135 ranges::for_each(*surfaces, reset);
138 std::stringstream unused_points_info;
139 unused_points_info << std::fixed;
143 ranges::views::zip(*points, used_points) |
144 ranges::views::filter([](
auto&& pair) {
return !pair.second; }) |
147 unused_points_info << point->getID() <<
" " << *point <<
'\n';
152 std::erase(*points,
nullptr);
153 if (!unused_points_info.str().empty())
155 INFO(
"Removed the following points:\n{}", unused_points_info.str());
158 WARN(
"Names of points are not handled correctly in every case.");
162 geo_output_arg.getValue());