15#include <tclap/CmdLine.h>
36 std::string
const& out_fname,
40 std::vector<std::size_t>
const& name_component_ids,
41 std::string& points_group_name,
44 int n_records(DBFGetRecordCount(dbf_handle));
45 INFO(
"Reading {:d} records.", n_records);
47 std::vector<GeoLib::Point*> points;
48 points.reserve(n_records);
51 for (
int k = 0; k < n_records; k++)
53 double x(DBFReadDoubleAttribute(dbf_handle, k, x_id));
54 double y(DBFReadDoubleAttribute(dbf_handle, k, y_id));
56 if (z_id != std::numeric_limits<std::size_t>::max())
58 z = DBFReadDoubleAttribute(dbf_handle, k, z_id);
62 if (!name_component_ids.empty())
64 for (
unsigned long name_component_id : name_component_ids)
66 if (name_component_id !=
67 std::numeric_limits<std::size_t>::max())
69 name += DBFReadStringAttribute(dbf_handle, k,
77 name = std::to_string(k);
83 points.push_back(pnt);
88 points.push_back(pnt);
99 geo_objs.
addPointVec(std::move(points), points_group_name,
118 std::size_t n_fields)
120 char* field_name(
new char[256]);
123 std::stringstream out;
125 out <<
"************************************************" << std::endl;
126 out <<
"field idx | name of field | data type of field " << std::endl;
127 out <<
"------------------------------------------------" << std::endl;
128 for (std::size_t field_idx(0); field_idx < n_fields; field_idx++)
130 DBFGetFieldInfo(dbf_handle, field_idx, field_name, &width, &n_decimals);
133 out <<
" " << field_idx <<
" |";
137 out <<
" " << field_idx <<
" |";
139 std::string field_name_str(field_name);
140 for (
int k(0); k < (14 -
static_cast<int>(field_name_str.size())); k++)
144 out << field_name_str <<
" |";
146 char native_field_type(DBFGetNativeFieldType(dbf_handle, field_idx));
147 switch (native_field_type)
150 out <<
" string" << std::endl;
153 out <<
" float" << std::endl;
156 out <<
" numeric" << std::endl;
159 out <<
" n_decimal " << n_decimals << std::endl;
164 out <<
"************************************************" << std::endl;
165 INFO(
"{:s}", out.str());
168int main(
int argc,
char* argv[])
171 "Converts points contained in shape file\n\n"
172 "OpenGeoSys-6 software, version " +
175 "Copyright (c) 2012-2024, OpenGeoSys Community "
176 "(http://www.opengeosys.org)",
178 TCLAP::ValueArg<std::string> shapefile_arg(
"s",
180 "the name of the shape file ",
184 cmd.add(shapefile_arg);
186 cmd.parse(argc, argv);
189 MPI_Init(&argc, &argv);
192 std::string fname(shapefile_arg.getValue());
195 int number_of_elements;
197 SHPHandle hSHP = SHPOpen(fname.c_str(),
"rb");
200 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
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))
207 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
208 ERR(
"This programme only handles only files containing points.");
219 ERR(
"Could not open shapefile {:s}.", fname);
222 DBFHandle dbf_handle = DBFOpen(fname.c_str(),
"rb");
225 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
232 "Please give the field idx that should be used for reading the x "
236 "Please give the field idx that should be used for reading the y "
240 "Please give the field idx that should be used for reading the z "
246 z_id = std::numeric_limits<std::size_t>::max();
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;
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)
257 for (std::size_t j(0); j < n_name_components; j++)
260 "- please give the field idx that should be used for "
261 "reading the name: ");
262 std::cin >> name_component_ids[j];
265 for (std::size_t j(0); j < n_name_components; j++)
267 if (name_component_ids[j] > n_fields)
269 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
273 std::size_t station(0);
276 "Should I read the information as GeoLib::Station (0) or as "
277 "GeoLib::Point (1)? Please give the number: ");
280 std::string fname_base(fname);
290 INFO(
"Writing to {:s}.", fname);
299 DBFClose(dbf_handle);
304 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