5#include <tclap/CmdLine.h>
21 std::string
const& out_fname,
25 std::vector<std::size_t>
const& name_component_ids,
26 std::string& points_group_name,
29 int n_records(DBFGetRecordCount(dbf_handle));
30 INFO(
"Reading {:d} records.", n_records);
32 std::vector<GeoLib::Point*> points;
33 points.reserve(n_records);
36 for (
int k = 0; k < n_records; k++)
38 double x(DBFReadDoubleAttribute(dbf_handle, k, x_id));
39 double y(DBFReadDoubleAttribute(dbf_handle, k, y_id));
41 if (z_id != std::numeric_limits<std::size_t>::max())
43 z = DBFReadDoubleAttribute(dbf_handle, k, z_id);
47 if (!name_component_ids.empty())
49 for (
unsigned long name_component_id : name_component_ids)
51 if (name_component_id !=
52 std::numeric_limits<std::size_t>::max())
54 name += DBFReadStringAttribute(dbf_handle, k,
62 name = std::to_string(k);
68 points.push_back(pnt);
73 points.push_back(pnt);
84 geo_objs.
addPointVec(std::move(points), points_group_name,
103 std::size_t n_fields)
105 char* field_name(
new char[256]);
108 std::stringstream out;
110 out <<
"************************************************" << std::endl;
111 out <<
"field idx | name of field | data type of field " << std::endl;
112 out <<
"------------------------------------------------" << std::endl;
113 for (std::size_t field_idx(0); field_idx < n_fields; field_idx++)
115 DBFGetFieldInfo(dbf_handle, field_idx, field_name, &width, &n_decimals);
118 out <<
" " << field_idx <<
" |";
122 out <<
" " << field_idx <<
" |";
124 std::string field_name_str(field_name);
125 for (
int k(0); k < (14 -
static_cast<int>(field_name_str.size())); k++)
129 out << field_name_str <<
" |";
131 char native_field_type(DBFGetNativeFieldType(dbf_handle, field_idx));
132 switch (native_field_type)
135 out <<
" string" << std::endl;
138 out <<
" float" << std::endl;
141 out <<
" numeric" << std::endl;
144 out <<
" n_decimal " << n_decimals << std::endl;
149 out <<
"************************************************" << std::endl;
150 INFO(
"{:s}", out.str());
153int main(
int argc,
char* argv[])
156 "Converts points contained in shape file\n\n"
157 "OpenGeoSys-6 software, version " +
160 "Copyright (c) 2012-2026, OpenGeoSys Community "
161 "(http://www.opengeosys.org)",
163 TCLAP::ValueArg<std::string> shapefile_arg(
166 "Input (.shp). The name of the input shape "
171 cmd.add(shapefile_arg);
174 cmd.add(log_level_arg);
175 cmd.parse(argc, argv);
180 std::string fname(shapefile_arg.getValue());
183 int number_of_elements;
185 SHPHandle hSHP = SHPOpen(fname.c_str(),
"rb");
188 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
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))
195 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
196 ERR(
"This programme only handles only files containing points.");
204 ERR(
"Could not open shapefile {:s}.", fname);
207 DBFHandle dbf_handle = DBFOpen(fname.c_str(),
"rb");
210 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
217 "Please give the field idx that should be used for reading the x "
221 "Please give the field idx that should be used for reading the y "
225 "Please give the field idx that should be used for reading the z "
231 z_id = std::numeric_limits<std::size_t>::max();
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;
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)
242 for (std::size_t j(0); j < n_name_components; j++)
245 "- please give the field idx that should be used for "
246 "reading the name: ");
247 std::cin >> name_component_ids[j];
250 for (std::size_t j(0); j < n_name_components; j++)
252 if (name_component_ids[j] > n_fields)
254 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
258 std::size_t station(0);
261 "Should I read the information as GeoLib::Station (0) or as "
262 "GeoLib::Point (1)? Please give the number: ");
265 std::string fname_base(fname);
275 INFO(
"Writing to {:s}.", fname);
284 DBFClose(dbf_handle);
289 ERR(
"Could not open the database file.");
int main(int argc, char *argv[])
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 INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
std::string writeToString()
Writes the object to a string.
Container class for geometric objects.
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Reads and writes GeoObjects to and from XML files.
Reads and writes Observation Sites to and from XML files.
A Station (observation site) is basically a Point with some additional information.
static Station * createStation(const std::string &line)
std::map< std::string, std::size_t > NameIdMap
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version