28 if (XMLQtInterface::readFile(fileName) == 0)
33 QDomDocument doc(
"OGS-STN-DOM");
35 QDomElement docElement =
36 doc.documentElement();
37 if (docElement.nodeName().compare(
"OpenGeoSysSTN"))
39 ERR(
"XmlStnInterface::readFile(): Unexpected XML root.");
43 QDomNodeList lists = docElement.childNodes();
44 for (
int i = 0; i < lists.count(); i++)
47 QDomNodeList stationList = lists.at(i).childNodes();
48 std::vector<GeoLib::Point*> stations;
49 std::string stnName(
"[NN]");
51 for (
int j = 0; j < stationList.count(); j++)
53 const QDomNode station_node(stationList.at(j));
54 const QString station_type(station_node.nodeName());
55 if (station_type.compare(
"name") == 0)
57 stnName = station_node.toElement().text().toStdString();
59 else if (station_type.compare(
"stations") == 0)
61 readStations(station_node, stations, fileName.toStdString());
63 else if (station_type.compare(
"boreholes") == 0)
65 readStations(station_node, stations, fileName.toStdString());
69 if (!stations.empty())
71 _geo_objs.addStationVec(std::move(stations), stnName);
79 std::vector<GeoLib::Point*>& stations,
80 const std::string& station_file_name)
82 QDomElement station = stationsRoot.firstChildElement();
83 while (!station.isNull())
85 if (station.hasAttribute(
"id") && station.hasAttribute(
"x") &&
86 station.hasAttribute(
"y"))
88 std::string stationName(
"[NN]");
89 std::string sensor_data_file_name;
90 std::string boreholeDate(
"0000-00-00");
91 double boreholeDepth(0.0);
92 double stationValue(0.0);
94 QDomNodeList stationFeatures = station.childNodes();
95 for (
int i = 0; i < stationFeatures.count(); i++)
98 const QDomNode feature_node(stationFeatures.at(i));
99 const QString feature_name(feature_node.nodeName());
100 const QString element_text(feature_node.toElement().text());
101 if (feature_name.compare(
"name") == 0)
103 stationName = element_text.toStdString();
105 if (feature_name.compare(
"sensordata") == 0)
107 sensor_data_file_name = element_text.toStdString();
112 else if (feature_name.compare(
"value") == 0)
114 stationValue = element_text.toDouble();
116 else if (feature_name.compare(
"bdepth") == 0)
118 boreholeDepth = element_text.toDouble();
120 else if (feature_name.compare(
"bdate") == 0)
122 boreholeDate = element_text.toStdString();
127 double zVal = (station.hasAttribute(
"z"))
128 ? station.attribute(
"z").toDouble()
131 if (station.nodeName().compare(
"station") == 0)
135 station.attribute(
"y").toDouble(),
139 if (!sensor_data_file_name.empty())
142 station_file_name, sensor_data_file_name));
144 stations.push_back(s);
146 else if (station.nodeName().compare(
"borehole") == 0)
151 station.attribute(
"x").toDouble(),
152 station.attribute(
"y").toDouble(),
158 for (
int j = 0; j < stationFeatures.count(); j++)
160 if (stationFeatures.at(j).nodeName().compare(
"strat") == 0)
166 stations.push_back(s);
172 "XmlStnInterface::readStations(): Attribute missing in "
175 station = station.nextSiblingElement();
184 double depth_check((*borehole)[2]);
185 QDomElement horizon = stratRoot.firstChildElement();
186 while (!horizon.isNull())
188 if (horizon.hasAttribute(
"id") && horizon.hasAttribute(
"x") &&
189 horizon.hasAttribute(
"y") && horizon.hasAttribute(
"z"))
191 std::string horizonName(
"[NN]");
193 QDomNodeList horizonFeatures = horizon.childNodes();
194 for (
int i = 0; i < horizonFeatures.count(); i++)
196 if (horizonFeatures.at(i).nodeName().compare(
"name") == 0)
199 horizonFeatures.at(i).toElement().text().toStdString();
204 double depth(horizon.attribute(
"z").toDouble());
205 if (std::abs(depth - depth_check) >
206 std::numeric_limits<double>::
209 borehole->
addSoilLayer(horizon.attribute(
"x").toDouble(),
210 horizon.attribute(
"y").toDouble(),
218 "XmlStnInterface::readStratigraphy(): Skipped layer '{:s}' "
219 "in borehole '{:s}' because of thickness 0.0.",
220 horizonName, borehole->
getName());
226 "XmlStnInterface::readStratigraphy(): Attribute missing in "
229 horizon = horizon.nextSiblingElement();
237 ERR(
"XmlStnInterface::write(): No station list specified.");
241 out <<
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
243 out <<
"<?xml-stylesheet type=\"text/xsl\" "
244 "href=\"OpenGeoSysSTN.xsl\"?>\n\n";
246 QDomDocument doc(
"OGS-STN-DOM");
247 QDomElement root = doc.createElement(
"OpenGeoSysSTN");
248 root.setAttribute(
"xmlns:ogs",
"http://www.opengeosys.org");
249 root.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
251 const std::vector<GeoLib::Point*>* stations(
253 bool const is_borehole =
256 doc.appendChild(root);
257 QDomElement stationListTag = doc.createElement(
"stationlist");
258 root.appendChild(stationListTag);
260 QDomElement listNameTag = doc.createElement(
"name");
261 stationListTag.appendChild(listNameTag);
262 QDomText stationListNameText =
263 doc.createTextNode(QString::fromStdString(
export_name));
264 listNameTag.appendChild(stationListNameText);
265 QString listType = is_borehole ?
"boreholes" :
"stations";
266 QDomElement stationsTag = doc.createElement(listType);
267 stationListTag.appendChild(stationsTag);
269 bool useStationValue(
false);
272 std::size_t nStations(stations->size());
273 for (std::size_t i = 1; i < nStations; i++)
275 if ((
static_cast<GeoLib::Station*
>((*stations)[i])->getStationValue() -
276 sValue) < std::numeric_limits<double>::epsilon())
278 useStationValue =
true;
283 for (std::size_t i = 0; i < nStations; i++)
285 QString stationType = is_borehole ?
"borehole" :
"station";
286 QDomElement stationTag = doc.createElement(stationType);
287 stationTag.setAttribute(
"id", QString::number(i));
288 stationTag.setAttribute(
289 "x", QString::number((*(*stations)[i])[0],
'f',
290 std::numeric_limits<double>::max_digits10));
291 stationTag.setAttribute(
292 "y", QString::number((*(*stations)[i])[1],
'f',
293 std::numeric_limits<double>::max_digits10));
294 stationTag.setAttribute(
295 "z", QString::number((*(*stations)[i])[2],
'f',
296 std::numeric_limits<double>::max_digits10));
297 stationsTag.appendChild(stationTag);
299 QDomElement stationNameTag = doc.createElement(
"name");
300 stationTag.appendChild(stationNameTag);
301 QDomText stationNameText = doc.createTextNode(QString::fromStdString(
303 stationNameTag.appendChild(stationNameText);
307 QDomElement stationValueTag = doc.createElement(
"value");
308 stationTag.appendChild(stationValueTag);
309 QDomText stationValueText = doc.createTextNode(
311 ->getStationValue()));
312 stationValueTag.appendChild(stationValueText);
323 std::string xml = doc.toString().toStdString();
329 QDomElement& boreholeTag,
332 QDomElement stationDepthTag = doc.createElement(
"bdepth");
333 boreholeTag.appendChild(stationDepthTag);
334 QDomText stationDepthText =
335 doc.createTextNode(QString::number(borehole->
getDepth(),
'f'));
336 stationDepthTag.appendChild(stationDepthText);
337 if (std::abs(borehole->
getDate()) > 0)
339 QDomElement stationDateTag = doc.createElement(
"bdate");
340 boreholeTag.appendChild(stationDateTag);
341 QDomText stationDateText = doc.createTextNode(
343 stationDateTag.appendChild(stationDateText);
346 std::vector<GeoLib::Point*> profile = borehole->
getProfile();
347 std::vector<std::string> soilNames = borehole->
getSoilNames();
348 std::size_t nHorizons(profile.size());
352 QDomElement stratTag = doc.createElement(
"strat");
353 boreholeTag.appendChild(stratTag);
355 for (std::size_t j = 1; j < nHorizons;
359 QDomElement horizonTag = doc.createElement(
"horizon");
360 horizonTag.setAttribute(
"id", QString::number(j));
361 horizonTag.setAttribute(
"x",
362 QString::number((*profile[j])[0],
'f'));
363 horizonTag.setAttribute(
"y",
364 QString::number((*profile[j])[1],
'f'));
365 horizonTag.setAttribute(
"z",
366 QString::number((*profile[j])[2],
'f'));
367 stratTag.appendChild(horizonTag);
368 QDomElement horizonNameTag = doc.createElement(
"name");
369 horizonTag.appendChild(horizonNameTag);
370 QDomText horizonNameText =
371 doc.createTextNode(QString::fromStdString(soilNames[j]));
372 horizonNameTag.appendChild(horizonNameText);
static StationBorehole * createStation(const std::string &name, double x, double y, double z, double depth, const std::string &date="")
Creates a new borehole object based on the given parameters.