169{
170 TCLAP::CmdLine cmd(
171 "Converts points contained in shape file\n\n"
172 "OpenGeoSys-6 software, version " +
174 ".\n"
175 "Copyright (c) 2012-2024, OpenGeoSys Community "
176 "(http://www.opengeosys.org)",
178 TCLAP::ValueArg<std::string> shapefile_arg("s",
179 "shape-file",
180 "the name of the shape file ",
181 true,
182 "",
183 "shape file");
184 cmd.add(shapefile_arg);
185
186 cmd.parse(argc, argv);
187
188#ifdef USE_PETSC
189 MPI_Init(&argc, &argv);
190#endif
191
192 std::string fname(shapefile_arg.getValue());
193
194 int shape_type;
195 int number_of_elements;
196
197 SHPHandle hSHP = SHPOpen(fname.c_str(), "rb");
198 if (hSHP)
199 {
200 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
201 nullptr , nullptr );
202
203 if ((shape_type - 1) % 10 == 0)
204 INFO(
"Shape file contains {:d} points.", number_of_elements);
205 if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0))
206 {
207 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
208 ERR(
"This programme only handles only files containing points.");
209 SHPClose(hSHP);
210#ifdef USE_PETSC
211 MPI_Finalize();
212#endif
213 return EXIT_SUCCESS;
214 }
215 SHPClose(hSHP);
216 }
217 else
218 {
219 ERR(
"Could not open shapefile {:s}.", fname);
220 }
221
222 DBFHandle dbf_handle = DBFOpen(fname.c_str(), "rb");
223 if (dbf_handle)
224 {
225 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
227
228 std::size_t x_id;
229 std::size_t y_id;
230 std::size_t z_id;
232 "Please give the field idx that should be used for reading the x "
233 "coordinate: ");
234 std::cin >> x_id;
236 "Please give the field idx that should be used for reading the y "
237 "coordinate: ");
238 std::cin >> y_id;
240 "Please give the field idx that should be used for reading the z "
241 "coordinate: ");
242 std::cin >> z_id;
243
244 if (z_id > n_fields)
245 {
246 z_id = std::numeric_limits<std::size_t>::max();
247 }
248
249 std::size_t n_name_components;
250 INFO(
"Please give the number of fields that should be added to name: ");
251 std::cin >> n_name_components;
252
253 std::vector<std::size_t> name_component_ids(
254 n_name_components, std::numeric_limits<std::size_t>::max());
255 if (n_name_components != 0)
256 {
257 for (std::size_t j(0); j < n_name_components; j++)
258 {
260 "- please give the field idx that should be used for "
261 "reading the name: ");
262 std::cin >> name_component_ids[j];
263 }
264 }
265 for (std::size_t j(0); j < n_name_components; j++)
266 {
267 if (name_component_ids[j] > n_fields)
268 {
269 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
270 }
271 }
272
273 std::size_t station(0);
274
276 "Should I read the information as GeoLib::Station (0) or as "
277 "GeoLib::Point (1)? Please give the number: ");
278 std::cin >> station;
279
280 std::string fname_base(fname);
281 if (station == 0)
282 {
283 fname += ".stn";
284 }
285 else
286 {
287 fname += ".gml";
288 }
289
290 INFO(
"Writing to {:s}.", fname);
292 fname,
293 x_id,
294 y_id,
295 z_id,
296 name_component_ids,
297 fname_base,
298 station == 0);
299 DBFClose(dbf_handle);
301 }
302 else
303 {
304 ERR(
"Could not open the database file.");
305 }
306
307#ifdef USE_PETSC
308 MPI_Finalize();
309#endif
310 return EXIT_SUCCESS;
311}
void convertPoints(DBFHandle dbf_handle, std::string const &out_fname, std::size_t x_id, std::size_t y_id, std::size_t z_id, std::vector< std::size_t > const &name_component_ids, std::string &points_group_name, bool station)
void printFieldInformationTable(DBFHandle const &dbf_handle, std::size_t n_fields)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
GITINFOLIB_EXPORT const std::string ogs_version