15#include <tclap/CmdLine.h>
31 std::string
const& out_fname,
35 std::vector<std::size_t>
const& name_component_ids,
36 std::string& points_group_name,
39 int n_records(DBFGetRecordCount(dbf_handle));
40 INFO(
"Reading {:d} records.", n_records);
42 std::vector<GeoLib::Point*> points;
43 points.reserve(n_records);
46 for (
int k = 0; k < n_records; k++)
48 double x(DBFReadDoubleAttribute(dbf_handle, k, x_id));
49 double y(DBFReadDoubleAttribute(dbf_handle, k, y_id));
51 if (z_id != std::numeric_limits<std::size_t>::max())
53 z = DBFReadDoubleAttribute(dbf_handle, k, z_id);
57 if (!name_component_ids.empty())
59 for (
unsigned long name_component_id : name_component_ids)
61 if (name_component_id !=
62 std::numeric_limits<std::size_t>::max())
64 name += DBFReadStringAttribute(dbf_handle, k,
72 name = std::to_string(k);
78 points.push_back(pnt);
83 points.push_back(pnt);
94 geo_objs.
addPointVec(std::move(points), points_group_name,
113 std::size_t n_fields)
115 char* field_name(
new char[256]);
118 std::stringstream out;
120 out <<
"************************************************" << std::endl;
121 out <<
"field idx | name of field | data type of field " << std::endl;
122 out <<
"------------------------------------------------" << std::endl;
123 for (std::size_t field_idx(0); field_idx < n_fields; field_idx++)
125 DBFGetFieldInfo(dbf_handle, field_idx, field_name, &width, &n_decimals);
128 out <<
" " << field_idx <<
" |";
132 out <<
" " << field_idx <<
" |";
134 std::string field_name_str(field_name);
135 for (
int k(0); k < (14 -
static_cast<int>(field_name_str.size())); k++)
139 out << field_name_str <<
" |";
141 char native_field_type(DBFGetNativeFieldType(dbf_handle, field_idx));
142 switch (native_field_type)
145 out <<
" string" << std::endl;
148 out <<
" float" << std::endl;
151 out <<
" numeric" << std::endl;
154 out <<
" n_decimal " << n_decimals << std::endl;
159 out <<
"************************************************" << std::endl;
160 INFO(
"{:s}", out.str());
163int main(
int argc,
char* argv[])
166 "Converts points contained in shape file\n\n"
167 "OpenGeoSys-6 software, version " +
170 "Copyright (c) 2012-2025, OpenGeoSys Community "
171 "(http://www.opengeosys.org)",
173 TCLAP::ValueArg<std::string> shapefile_arg(
176 "Input (.shp). The name of the input shape "
181 cmd.add(shapefile_arg);
184 cmd.add(log_level_arg);
185 cmd.parse(argc, argv);
190 std::string fname(shapefile_arg.getValue());
193 int number_of_elements;
195 SHPHandle hSHP = SHPOpen(fname.c_str(),
"rb");
198 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
201 if ((shape_type - 1) % 10 == 0)
202 INFO(
"Shape file contains {:d} points.", number_of_elements);
203 if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0))
205 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
206 ERR(
"This programme only handles only files containing points.");
214 ERR(
"Could not open shapefile {:s}.", fname);
217 DBFHandle dbf_handle = DBFOpen(fname.c_str(),
"rb");
220 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
227 "Please give the field idx that should be used for reading the x "
231 "Please give the field idx that should be used for reading the y "
235 "Please give the field idx that should be used for reading the z "
241 z_id = std::numeric_limits<std::size_t>::max();
244 std::size_t n_name_components;
245 INFO(
"Please give the number of fields that should be added to name: ");
246 std::cin >> n_name_components;
248 std::vector<std::size_t> name_component_ids(
249 n_name_components, std::numeric_limits<std::size_t>::max());
250 if (n_name_components != 0)
252 for (std::size_t j(0); j < n_name_components; j++)
255 "- please give the field idx that should be used for "
256 "reading the name: ");
257 std::cin >> name_component_ids[j];
260 for (std::size_t j(0); j < n_name_components; j++)
262 if (name_component_ids[j] > n_fields)
264 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
268 std::size_t station(0);
271 "Should I read the information as GeoLib::Station (0) or as "
272 "GeoLib::Point (1)? Please give the number: ");
275 std::string fname_base(fname);
285 INFO(
"Writing to {:s}.", fname);
294 DBFClose(dbf_handle);
299 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)
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Station class.
Definition of the XmlGmlInterface class.
Definition of the XmlStnInterface class.
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