15#include <tclap/CmdLine.h>
33 std::string
const& out_fname,
37 std::vector<std::size_t>
const& name_component_ids,
38 std::string& points_group_name,
41 int n_records(DBFGetRecordCount(dbf_handle));
42 INFO(
"Reading {:d} records.", n_records);
44 std::vector<GeoLib::Point*> points;
45 points.reserve(n_records);
48 for (
int k = 0; k < n_records; k++)
50 double x(DBFReadDoubleAttribute(dbf_handle, k, x_id));
51 double y(DBFReadDoubleAttribute(dbf_handle, k, y_id));
53 if (z_id != std::numeric_limits<std::size_t>::max())
55 z = DBFReadDoubleAttribute(dbf_handle, k, z_id);
59 if (!name_component_ids.empty())
61 for (
unsigned long name_component_id : name_component_ids)
63 if (name_component_id !=
64 std::numeric_limits<std::size_t>::max())
66 name += DBFReadStringAttribute(dbf_handle, k,
74 name = std::to_string(k);
80 points.push_back(pnt);
85 points.push_back(pnt);
96 geo_objs.
addPointVec(std::move(points), points_group_name,
115 std::size_t n_fields)
117 char* field_name(
new char[256]);
120 std::stringstream out;
122 out <<
"************************************************" << std::endl;
123 out <<
"field idx | name of field | data type of field " << std::endl;
124 out <<
"------------------------------------------------" << std::endl;
125 for (std::size_t field_idx(0); field_idx < n_fields; field_idx++)
127 DBFGetFieldInfo(dbf_handle, field_idx, field_name, &width, &n_decimals);
130 out <<
" " << field_idx <<
" |";
134 out <<
" " << field_idx <<
" |";
136 std::string field_name_str(field_name);
137 for (
int k(0); k < (14 -
static_cast<int>(field_name_str.size())); k++)
141 out << field_name_str <<
" |";
143 char native_field_type(DBFGetNativeFieldType(dbf_handle, field_idx));
144 switch (native_field_type)
147 out <<
" string" << std::endl;
150 out <<
" float" << std::endl;
153 out <<
" numeric" << std::endl;
156 out <<
" n_decimal " << n_decimals << std::endl;
161 out <<
"************************************************" << std::endl;
162 INFO(
"{:s}", out.str());
165int main(
int argc,
char* argv[])
168 "Converts points contained in shape file\n\n"
169 "OpenGeoSys-6 software, version " +
172 "Copyright (c) 2012-2024, OpenGeoSys Community "
173 "(http://www.opengeosys.org)",
175 TCLAP::ValueArg<std::string> shapefile_arg(
"s",
177 "the name of the shape file ",
181 cmd.add(shapefile_arg);
183 cmd.parse(argc, argv);
187 std::string fname(shapefile_arg.getValue());
190 int number_of_elements;
192 SHPHandle hSHP = SHPOpen(fname.c_str(),
"rb");
195 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
198 if ((shape_type - 1) % 10 == 0)
199 INFO(
"Shape file contains {:d} points.", number_of_elements);
200 if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0))
202 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
203 ERR(
"This programme only handles only files containing points.");
211 ERR(
"Could not open shapefile {:s}.", fname);
214 DBFHandle dbf_handle = DBFOpen(fname.c_str(),
"rb");
217 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
224 "Please give the field idx that should be used for reading the x "
228 "Please give the field idx that should be used for reading the y "
232 "Please give the field idx that should be used for reading the z "
238 z_id = std::numeric_limits<std::size_t>::max();
241 std::size_t n_name_components;
242 INFO(
"Please give the number of fields that should be added to name: ");
243 std::cin >> n_name_components;
245 std::vector<std::size_t> name_component_ids(
246 n_name_components, std::numeric_limits<std::size_t>::max());
247 if (n_name_components != 0)
249 for (std::size_t j(0); j < n_name_components; j++)
252 "- please give the field idx that should be used for "
253 "reading the name: ");
254 std::cin >> name_component_ids[j];
257 for (std::size_t j(0); j < n_name_components; j++)
259 if (name_component_ids[j] > n_fields)
261 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
265 std::size_t station(0);
268 "Should I read the information as GeoLib::Station (0) or as "
269 "GeoLib::Point (1)? Please give the number: ");
272 std::string fname_base(fname);
282 INFO(
"Writing to {:s}.", fname);
291 DBFClose(dbf_handle);
296 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)
GITINFOLIB_EXPORT const std::string ogs_version