16 #include <tclap/CmdLine.h>
32 std::string
const& out_fname,
36 std::vector<std::size_t>
const& name_component_ids,
37 std::string& points_group_name,
40 int n_records(DBFGetRecordCount(dbf_handle));
41 INFO(
"Reading {:d} records.", n_records);
43 auto points = std::make_unique<std::vector<GeoLib::Point*>>();
44 points->reserve(n_records);
47 for (
int k = 0; k < n_records; k++)
49 double x(DBFReadDoubleAttribute(dbf_handle, k, x_id));
50 double y(DBFReadDoubleAttribute(dbf_handle, k, y_id));
52 if (z_id != std::numeric_limits<std::size_t>::max())
54 z = DBFReadDoubleAttribute(dbf_handle, k, z_id);
58 if (!name_component_ids.empty())
60 for (
unsigned long name_component_id : name_component_ids)
62 if (name_component_id !=
63 std::numeric_limits<std::size_t>::max())
65 name += DBFReadStringAttribute(dbf_handle, k,
73 name = std::to_string(k);
79 points->push_back(pnt);
84 points->push_back(pnt);
95 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());
163 int main(
int argc,
char* argv[])
166 "Converts points contained in shape file\n\n"
167 "OpenGeoSys-6 software, version " +
170 "Copyright (c) 2012-2021, OpenGeoSys Community "
171 "(http://www.opengeosys.org)",
173 TCLAP::ValueArg<std::string> shapefile_arg(
"s",
175 "the name of the shape file ",
179 cmd.add(shapefile_arg);
181 cmd.parse(argc, argv);
183 std::string fname(shapefile_arg.getValue());
186 int number_of_elements;
188 SHPHandle hSHP = SHPOpen(fname.c_str(),
"rb");
191 SHPGetInfo(hSHP, &number_of_elements, &shape_type,
194 if ((shape_type - 1) % 10 == 0)
195 INFO(
"Shape file contains {:d} points.", number_of_elements);
196 if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0))
198 ERR(
"Shape file contains {:d} polylines.", number_of_elements);
199 ERR(
"This programme only handles only files containing points.");
207 ERR(
"Could not open shapefile {:s}.", fname);
210 DBFHandle dbf_handle = DBFOpen(fname.c_str(),
"rb");
213 std::size_t n_fields(DBFGetFieldCount(dbf_handle));
220 "Please give the field idx that should be used for reading the x "
224 "Please give the field idx that should be used for reading the y "
228 "Please give the field idx that should be used for reading the z "
234 z_id = std::numeric_limits<std::size_t>::max();
237 std::size_t n_name_components;
238 INFO(
"Please give the number of fields that should be added to name: ");
239 std::cin >> n_name_components;
241 std::vector<std::size_t> name_component_ids(
242 n_name_components, std::numeric_limits<std::size_t>::max());
243 if (n_name_components != 0)
245 for (std::size_t j(0); j < n_name_components; j++)
248 "- please give the field idx that should be used for "
249 "reading the name: ");
250 std::cin >> name_component_ids[j];
253 for (std::size_t j(0); j < n_name_components; j++)
255 if (name_component_ids[j] > n_fields)
257 name_component_ids[j] = std::numeric_limits<std::size_t>::max();
261 std::size_t station(0);
264 "Should I read the information as GeoLib::Station (0) or as "
265 "GeoLib::Point (1)? Please give the number: ");
268 std::string fname_base(fname);
278 INFO(
"Writing to {:s}.", fname);
287 DBFClose(dbf_handle);
292 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(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... 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 addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
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)
Creates a Station-object from information contained in a string (assuming the string has the right fo...
int writeStringToFile(std::string content, std::filesystem::path const &file_path)
GITINFOLIB_EXPORT const std::string ogs_version