154{
155 TCLAP::CmdLine cmd(
156 "Converts points contained in shape file\n\n"
157 "OpenGeoSys-6 software, version " +
159 ".\n"
160 "Copyright (c) 2012-2026, OpenGeoSys Community "
161 "(http://www.opengeosys.org)",
163 TCLAP::ValueArg<std::string> shapefile_arg(
164 "s",
165 "shape-file",
166 "Input (.shp). The name of the input shape "
167 "file",
168 true,
169 "",
170 "INPUT_FILE");
171 cmd.add(shapefile_arg);
172
174 cmd.add(log_level_arg);
175 cmd.parse(argc, argv);
176
179
180 std::string fname(shapefile_arg.getValue());
181
182 int shape_type;
183 int number_of_elements;
184
185 SHPHandle hSHP = SHPOpen(fname.c_str(), "rb");
186 if (hSHP)
187 {
188 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
189 nullptr , nullptr );
190
191 if ((shape_type - 1) % 10 == 0)
192 INFO(
"Shape file contains {:d} points.", number_of_elements);
193 if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0))
194 {
195 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
196 ERR(
"This programme only handles only files containing points.");
197 SHPClose(hSHP);
198 return EXIT_SUCCESS;
199 }
200 SHPClose(hSHP);
201 }
202 else
203 {
204 ERR(
"Could not open shapefile {:s}.", fname);
205 }
206
207 DBFHandle dbf_handle = DBFOpen(fname.c_str(), "rb");
208 if (dbf_handle)
209 {
210 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
212
213 std::size_t x_id;
214 std::size_t y_id;
215 std::size_t z_id;
217 "Please give the field idx that should be used for reading the x "
218 "coordinate: ");
219 std::cin >> x_id;
221 "Please give the field idx that should be used for reading the y "
222 "coordinate: ");
223 std::cin >> y_id;
225 "Please give the field idx that should be used for reading the z "
226 "coordinate: ");
227 std::cin >> z_id;
228
229 if (z_id > n_fields)
230 {
231 z_id = std::numeric_limits<std::size_t>::max();
232 }
233
234 std::size_t n_name_components;
235 INFO(
"Please give the number of fields that should be added to name: ");
236 std::cin >> n_name_components;
237
238 std::vector<std::size_t> name_component_ids(
239 n_name_components, std::numeric_limits<std::size_t>::max());
240 if (n_name_components != 0)
241 {
242 for (std::size_t j(0); j < n_name_components; j++)
243 {
245 "- please give the field idx that should be used for "
246 "reading the name: ");
247 std::cin >> name_component_ids[j];
248 }
249 }
250 for (std::size_t j(0); j < n_name_components; j++)
251 {
252 if (name_component_ids[j] > n_fields)
253 {
254 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
255 }
256 }
257
258 std::size_t station(0);
259
261 "Should I read the information as GeoLib::Station (0) or as "
262 "GeoLib::Point (1)? Please give the number: ");
263 std::cin >> station;
264
265 std::string fname_base(fname);
266 if (station == 0)
267 {
268 fname += ".stn";
269 }
270 else
271 {
272 fname += ".gml";
273 }
274
275 INFO(
"Writing to {:s}.", fname);
277 fname,
278 x_id,
279 y_id,
280 z_id,
281 name_component_ids,
282 fname_base,
283 station == 0);
284 DBFClose(dbf_handle);
286 }
287 else
288 {
289 ERR(
"Could not open the database file.");
290 }
291
292 return EXIT_SUCCESS;
293}
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)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version