diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.cpp deleted file mode 100644 index e0eb7e0fdd..0000000000 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * This file is part of Hootenanny. - * - * Hootenanny is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * -------------------------------------------------------------------- - * - * The following copyright notices are generated automatically. If you - * have a new notice to add, please use the format: - * " * @copyright Copyright ..." - * This will properly maintain the copyright information. Maxar - * copyrights will be updated automatically. - * - * @copyright Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) - */ -#include "OsmGbdxJsonWriter.h" - -// Hoot -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Qt -#include -#include -#include -#include - -using namespace geos::geom; -using namespace std; - -namespace hoot -{ - -HOOT_FACTORY_REGISTER(OsmMapWriter, OsmGbdxJsonWriter) - -OsmGbdxJsonWriter::OsmGbdxJsonWriter(int precision) - : OsmGeoJsonWriterBase(precision), - _fileNumber(0) -{ - _writeHootFormat = false; -} - -void OsmGbdxJsonWriter::open(const QString& path) -{ - QFileInfo fi(path); - _outputDir = fi.absoluteDir(); - _outputFileName = fi.baseName(); - - if (!_outputDir.exists() && !FileUtils::makeDir(_outputDir.path())) - throw HootException("Error creating directory for writing."); -} - -void OsmGbdxJsonWriter::_newOutputFile() -{ - // Close the old file and open a new one - if (_fp.isOpen()) - close(); - - // The output has had a few changes..... - QString url = _outputDir.filePath(QString("%1_00_%2.json").arg(_outputFileName).arg(_fileNumber++)); - - // If the file exists, increment the middle _00_ in the name. - // NOTE: This assumes that there can be a maximum of 10 copies of a filename.... - if (QFile::exists(url)) - { - int inc = 0; - while (QFile::exists(url)) - { - inc++; - url = _outputDir.filePath(QString("%1_%2_%3.json").arg(_outputFileName).arg(inc, 2, 10, QChar('0')).arg(_fileNumber)); - } - } - - _fp.setFileName(url); - - if (!_fp.open(QIODevice::WriteOnly | QIODevice::Text)) - throw HootException(QObject::tr("Error opening %1 for writing").arg(url)); - - _out = &_fp; -} - -void OsmGbdxJsonWriter::write(const ConstOsmMapPtr& map) -{ - _map = map; - - _writeNodes(); - _writeWays(); - _writeRelations(); - - // This will move out of here eventually. - close(); -} - -void OsmGbdxJsonWriter::_writeNodes() -{ - NoInformationCriterion crit; - vector nids; - const NodeMap& nodes = _map->getNodes(); - for (auto it = nodes.begin(); it != nodes.end(); ++it) - { - if (!crit.isSatisfied(_map->getNode(it->first))) - nids.push_back(it->first); - } - // sort the values to give consistent results. - sort(nids.begin(), nids.end(), greater()); - for (auto node_id : nids) - { - _newOutputFile(); - _writeNode(_map->getNode(node_id)); - } -} - -void OsmGbdxJsonWriter::_writeWays() -{ - const WayMap& ways = _map->getWays(); - for (auto it = ways.begin(); it != ways.end(); ++it) - { - ConstWayPtr w = it->second; - // Skip any ways that have parents - set parents = _map->getParents(w->getElementId()); - if (!parents.empty()) - continue; - if (w.get() == nullptr) - continue; - - // Make sure that building ways are "complete" - const vector& nodes = w->getNodeIds(); - bool valid = true; - if (AreaCriterion().isSatisfied(w)) - { - for (auto node_id : nodes) - { - ConstNodePtr node = _map->getNode(node_id); - if (node.get() == nullptr) - { - valid = false; - break; - } - } - } - // Write out the way in Gbdxjson if valid - if (valid) - { - _newOutputFile(); - _writeWay(w); - } - else - { - for (auto node_id : nodes) - { - ConstNodePtr node = _map->getNode(node_id); - if (node.get() != nullptr) - { - _newOutputFile(); - _writeNode(node); - } - } - } - } -} - -void OsmGbdxJsonWriter::_writeRelations() -{ - const RelationMap& relations = _map->getRelations(); - for (auto it = relations.begin(); it != relations.end(); ++it) - { - ConstRelationPtr r = it->second; - // Write out the relation (and all children) in geojson - _newOutputFile(); - _write("{"); - _writeFeature(r); - _write(","); - _write("\"geometry\": {"); - _writeGeometry(r); - _write("}"); - _write("}", false); - } -} - -} diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.h b/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.h deleted file mode 100644 index 14bd0a5ea9..0000000000 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxJsonWriter.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of Hootenanny. - * - * Hootenanny is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * -------------------------------------------------------------------- - * - * The following copyright notices are generated automatically. If you - * have a new notice to add, please use the format: - * " * @copyright Copyright ..." - * This will properly maintain the copyright information. Maxar - * copyrights will be updated automatically. - * - * @copyright Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) - */ -#ifndef OSM_GBDX_JSON_WRITER -#define OSM_GBDX_JSON_WRITER - -// hoot -#include -#include - -namespace hoot -{ - -/** - * Writes an OsmMap to JSON files with one feature per file. - * This is to support ingest into GBDX Vector Services. - */ -class OsmGbdxJsonWriter : public OsmGeoJsonWriterBase -{ -public: - - static QString className() { return "OsmGbdxJsonWriter"; } - - OsmGbdxJsonWriter(int precision = ConfigOptions().getWriterPrecision()); - ~OsmGbdxJsonWriter() override = default; - - /** - * @brief Create a directory to hold all of the GeoJSON files - * @param url - */ - void open(const QString& path) override; - - /** - * @brief write Write the OsmMap out in GeoJSON format with one feature per file, writer must be "open" - * @param map - */ - void write(const ConstOsmMapPtr& map) override; - /** - * @brief isSupported returns true if the URL is likely supported - * @param url Filename ending in ".gbdx" - * @return - */ - bool isSupported(const QString& url) const override { return url.endsWith(".gbdx", Qt::CaseInsensitive); } - - QString supportedFormats() const override { return ".gdbx"; } - -protected: - - /** - * @brief _writeNodes Iterates all nodes that aren't part of another element and writes - * them out individual GeoJSON files - */ - void _writeNodes() override; - /** - * @brief _writeWays Iterates all ways that aren't part of another element and writes - * them out individual GeoJSON files - */ - void _writeWays() override; - /** - * @brief _writeRelations Iterates all relations that aren't part of another element and writes - * them out individual GeoJSON files - */ - void _writeRelations() override; - -private: - - QDir _outputDir; - QString _outputFileName; - int _fileNumber; - - /** - * @brief Close the open file and open a unique file for output - */ - void _newOutputFile(); - -}; - -} - -#endif // OSM_GBDX_JSON_WRITER diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.cpp b/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.cpp deleted file mode 100644 index 0be4087ac6..0000000000 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.cpp +++ /dev/null @@ -1,599 +0,0 @@ -/* - * This file is part of Hootenanny. - * - * Hootenanny is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * -------------------------------------------------------------------- - * - * The following copyright notices are generated automatically. If you - * have a new notice to add, please use the format: - * " * @copyright Copyright ..." - * This will properly maintain the copyright information. Maxar - * copyrights will be updated automatically. - * - * @copyright Copyright (C) 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/) - */ -#include "OsmGbdxXmlWriter.h" - -// Hoot -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Qt -#include -#include -#include - -using namespace geos::geom; -using namespace std; - -namespace hoot -{ - -int OsmGbdxXmlWriter::logWarnCount = 0; - -HOOT_FACTORY_REGISTER(OsmMapWriter, OsmGbdxXmlWriter) - -OsmGbdxXmlWriter::OsmGbdxXmlWriter() - : _formatXml(ConfigOptions().getWriterXmlFormat()), - _precision(ConfigOptions().getWriterPrecision()), - _encodingErrorCount(0), - _fileNumber(0) -{ -} - -OsmGbdxXmlWriter::~OsmGbdxXmlWriter() -{ - close(); -} - -QString OsmGbdxXmlWriter::removeInvalidCharacters(const QString& s) -{ - // See Redmine #3553 for an explanation. - - QString result; - result.reserve(s.size()); - - bool foundError = false; - for (const auto& c : s) - { - // See http://stackoverflow.com/questions/730133/invalid-characters-in-xml - if (c < 0x20 && c != 0x9 && c != 0xA && c != 0xD) - foundError = true; - else - result.append(c); - } - - if (foundError) - { - _encodingErrorCount++; - if (logWarnCount < Log::getWarnMessageLimit()) - { - LOG_WARN("Found an invalid character in string: '" << s << "'"); - LOG_WARN(" UCS-4 version of the string: " << s.toUcs4()); - } - else if (logWarnCount == Log::getWarnMessageLimit()) - { - LOG_WARN(className() << ": " << Log::LOG_WARN_LIMIT_REACHED_MESSAGE); - } - logWarnCount++; - } - - return result; -} - -void OsmGbdxXmlWriter::open(const QString& url) -{ - QFileInfo fi(url); - _outputDir = fi.absoluteDir(); - _outputFileName = fi.baseName(); - - if (_outputDir.exists() == false && FileUtils::makeDir(_outputDir.path()) == false) - throw HootException("Error creating directory for writing."); - - _bounds.init(); -} - -void OsmGbdxXmlWriter::_newOutputFile() -{ - // Close the old file and open a new one Calling this so that the XML elements & document get closed - if (_fp.get()) - close(); - - // The output has had a few changes..... - QString url = _outputDir.filePath(QString("%1_00_%2.xml").arg(_outputFileName).arg(_fileNumber++)); - - // If the file exists, increment the middle _00_ in the name. - // NOTE: This assumes that there can be a maximum of 10 copies of a filename.... - if (QFile::exists(url)) - { - int inc = 0; - while (QFile::exists(url)) - { - inc++; - url = _outputDir.filePath(QString("%1_%2_%3.xml").arg(_outputFileName).arg(inc, 2, 10, QChar('0')).arg(_fileNumber)); - } - } - - _fp = std::make_shared(); - std::dynamic_pointer_cast(_fp)->setFileName(url); - - if (!_fp->open(QIODevice::WriteOnly | QIODevice::Text)) - throw HootException(QObject::tr("Error opening %1 for writing").arg(url)); - - _writer = std::make_shared(_fp.get()); - _writer->setCodec("UTF-8"); - - if (_formatXml) - _writer->setAutoFormatting(true); - - _writer->writeStartDocument(); - _writer->writeStartElement("metadata"); - -} - -void OsmGbdxXmlWriter::close() -{ - if (_writer.get()) - { - _writer->writeEndElement(); - _writer->writeEndDocument(); - } - - if (_fp.get()) - _fp->close(); -} - -QString OsmGbdxXmlWriter::toString(const ConstOsmMapPtr& map, const bool formatXml) -{ - OsmGbdxXmlWriter writer; - writer.setFormatXml(formatXml); - // This will be deleted by the _fp std::shared_ptr. - std::shared_ptr buf = std::make_shared(); - writer._fp = buf; - if (!writer._fp->open(QIODevice::WriteOnly | QIODevice::Text)) - throw InternalErrorException(QObject::tr("Error opening QBuffer for writing. Odd.")); - - writer.write(map); - return QString::fromUtf8(buf->data(), static_cast(buf->size())); -} - -QString OsmGbdxXmlWriter::_typeName(ElementType e) -{ - switch(e.getEnum()) - { - case ElementType::Node: - return "node"; - case ElementType::Way: - return "way"; - case ElementType::Relation: - return "relation"; - default: - throw HootException("Unexpected element type."); - } -} - -void OsmGbdxXmlWriter::write(const ConstOsmMapPtr& map, const QString& path) -{ - open(path); - write(map); -} - -void OsmGbdxXmlWriter::write(const ConstOsmMapPtr& map) -{ - _writeNodes(map); - _writeWays(map); - _writeRelations(map); - - close(); -} - -void OsmGbdxXmlWriter::_writeTags(const ConstElementPtr& element) -{ - // GBDX XML format: - // English - const Tags& tags = element->getTags(); - - for (auto it = tags.constBegin(); it != tags.constEnd(); ++it) - { - const QString key = it.key(); - const QString val = it.value().trimmed(); - - // Skip the empty stuff - if (val.isEmpty()) - continue; - - // Skip the Detection ID. This goes in the geometery area - if (key == "Det_id") - continue; - - // Dump the raw GBDX attributes into a CDATA block - if (key == "raw_gbdx") - { - _writer->writeStartElement(removeInvalidCharacters(key)); - _writer->writeCDATA(removeInvalidCharacters(val)); - _writer->writeEndElement(); - continue; - } - - // Keywords can be a list - if (key == "Kywrd" || key == "Src_imgid" || key == "Pltfrm_id" || key == "Ins_Type") - { - _writer->writeStartElement(key); - QStringList l = val.split(";"); - for (const auto& keyword : qAsConst(l)) - { - _writer->writeStartElement("value"); - _writer->writeCharacters(removeInvalidCharacters(keyword)); - _writer->writeEndElement(); - } - _writer->writeEndElement(); - continue; - } - - // Write out the Tag - _writer->writeStartElement(removeInvalidCharacters(key)); - _writer->writeCharacters(removeInvalidCharacters(val)); - _writer->writeEndElement(); - } -} - -void OsmGbdxXmlWriter::_writeNodes(ConstOsmMapPtr map) -{ - NoInformationCriterion crit; - QList nids; - const NodeMap& nodes = map->getNodes(); - for (auto it = nodes.begin(); it != nodes.end(); ++it) - { - if (!crit.isSatisfied(map->getNode(it->first))) - nids.append(it->first); - } - - // sort the values to give consistent results. - qSort(nids.begin(), nids.end(), qLess()); - for (auto node_id : qAsConst(nids)) - { - _newOutputFile(); - writePartial(map->getNode(node_id)); - } -} - -void OsmGbdxXmlWriter::_writeWays(ConstOsmMapPtr map) -{ - const WayMap& ways = map->getWays(); - - for (auto it = ways.begin(); it != ways.end(); ++it) - { - ConstWayPtr w = it->second; - - // Skip if null - if (w.get() == nullptr) - continue; - - // Skip any ways that have parents - set parents = map->getParents(w->getElementId()); - if (!parents.empty()) - continue; - - // Make sure that building ways are "complete" - const vector& nodes = w->getNodeIds(); - bool valid = true; - if (AreaCriterion().isSatisfied(w)) - { - for (auto node_id : nodes) - { - ConstNodePtr node = map->getNode(node_id); - if (node.get() == nullptr) - { - valid = false; - break; - } - } - } - // Write out the way in GbdxXml if valid - if (valid) - { - _newOutputFile(); - _writeWayWithPoints(w,map); - } - else - { - for (auto node_id : nodes) - { - ConstNodePtr node = map->getNode(node_id); - if (node.get() != nullptr) - { - LOG_INFO("Writing Nodes XXX"); - _newOutputFile(); - writePartial(node); - } - } - } - } - -} - -void OsmGbdxXmlWriter::_writeRelations(ConstOsmMapPtr map) -{ - QList rids; - const RelationMap& relations = map->getRelations(); - for (auto it = relations.begin(); it != relations.end(); ++it) - rids.append(it->first); - - // sort the values to give consistent results. - qSort(rids.begin(), rids.end(), qLess()); - for (auto relation_id : qAsConst(rids)) - { - _newOutputFile(); - _writeRelationWithPoints(map->getRelation(relation_id),map); - } -} - -void OsmGbdxXmlWriter::_writeBounds(const Envelope& bounds) const -{ - _writer->writeStartElement("bounds"); - _writer->writeAttribute("minlat", QString::number(bounds.getMinY(), 'g', _precision)); - _writer->writeAttribute("minlon", QString::number(bounds.getMinX(), 'g', _precision)); - _writer->writeAttribute("maxlat", QString::number(bounds.getMaxY(), 'g', _precision)); - _writer->writeAttribute("maxlon", QString::number(bounds.getMaxX(), 'g', _precision)); - _writer->writeEndElement(); -} - -void OsmGbdxXmlWriter::writePartial(const ConstNodePtr& n) -{ - LOG_VART(n); - - // WKT Format: - // POINT (30 10) - - _writer->writeStartElement("Location"); - _writer->writeCharacters(QString("POINT (%1 %2)").arg(QString::number(n->getX(), 'f', _precision), QString::number(n->getY(), 'f', _precision))); - _writer->writeEndElement(); - - _writeTags(n); -} - -void OsmGbdxXmlWriter::_writeWayWithPoints(const ConstWayPtr& w, ConstOsmMapPtr map) -{ - LOG_VART(w); - -// GBDX XML Format: -// -// -// -// 62.7477649302 -// 29.2851062801 -// Point -// -// 0 -// -// 5 -// 41RMN755396 -// -// Feature -// - - _writer->writeStartElement("Det_Val"); - _writer->writeStartElement("features"); - _writer->writeStartElement("geometry"); - _writer->writeStartElement("WKT"); - - // WKT Format: - // LINESTRING (30 10, 10 30, 40 40) - // POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)) - // POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30)) - - QString endBracket; - - const vector& nodes = w->getNodeIds(); - if (AreaCriterion().isSatisfied(w) || nodes[0] == nodes[nodes.size() - 1]) - { - endBracket = "))"; - _writer->writeCharacters(QString("POLYGON ((")); - } - else - { - endBracket = ")"; - _writer->writeCharacters(QString("LINESTRING (")); - } - - bool first = true; - for (auto nid : w->getNodeIds()) - { - if (first) - first = false; - else - _writer->writeCharacters(QString(", ")); - - ConstNodePtr n = map->getNode(nid); - _writer->writeCharacters(QString("%1 %2").arg(QString::number(n->getX(), 'f', _precision), QString::number(n->getY(), 'f', _precision))); - } - _writer->writeCharacters(endBracket); - - _writer->writeEndElement(); // WKT - - _writer->writeEndElement(); // geometry - - // Add the Det_id from the Tag - _writer->writeStartElement("id"); - _writer->writeCharacters(w->getTags()["Det_id"]); - _writer->writeEndElement(); - - _writer->writeEndElement(); // features - - _writer->writeEndElement(); // Det_Val - - _writeTags(w); -} - -void OsmGbdxXmlWriter::writePartial(const ConstWayPtr& w) -{ - LOG_VARI(w); - - _writer->writeStartElement("Partial way"); - _writer->writeAttribute("visible", "true"); - _writer->writeAttribute("id", QString::number(w->getId())); - - for (auto nid : w->getNodeIds()) - { - _writer->writeStartElement("nd"); - _writer->writeAttribute("ref", QString::number(nid)); - _writer->writeEndElement(); - } - - _writeTags(w); - - _writer->writeEndElement(); -} - -void OsmGbdxXmlWriter::writePartial(const ConstRelationPtr& r) -{ - LOG_VART(r); - - _writer->writeStartElement("XX relation"); - _writer->writeAttribute("visible", "true"); - _writer->writeAttribute("id", QString::number(r->getId())); - _writer->writeAttribute("type", r->getType()); - - const vector& members = r->getMembers(); - for (const auto& e : members) - { - _writer->writeStartElement("member"); - _writer->writeAttribute("type", _typeName(e.getElementId().getType())); - _writer->writeAttribute("ref", QString::number(e.getElementId().getId())); - _writer->writeAttribute("role", removeInvalidCharacters(e.getRole())); - _writer->writeEndElement(); - } - - _writeTags(r); - - _writer->writeEndElement(); -} - -void OsmGbdxXmlWriter::_writeRelationWithPoints(const ConstRelationPtr& r, ConstOsmMapPtr map) -{ - LOG_VART(r); - - _writer->writeStartElement("Det_Val"); - - _writer->writeStartElement("features"); - _writer->writeStartElement("geometry"); - _writer->writeStartElement("WKT"); - - // The format is: - // MULTIPOINT (10 40, 40 30, 20 20, 30 10) - // MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10)) - // MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5))) - // MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20))) - - - QString featureGeometry(r->getType()); - QString startBracket; - QString endBracket; - - if (featureGeometry == MetadataTags::RelationMultiPolygon()) - { - featureGeometry = "MultiPolygon"; - startBracket = "(("; - endBracket = "))"; - } - else if (featureGeometry == MetadataTags::RelationMultilineString()) - { - featureGeometry = "MultiLineString"; - startBracket = "("; - endBracket = ")"; - } - else if (featureGeometry == MetadataTags::RelationMultiPoint()) - { - featureGeometry = "MultiPoint"; - startBracket = ""; - endBracket = ""; - } - - _writer->writeCharacters(featureGeometry.toUpper() + QString(" (")); - - bool firstRel = true; - const vector& members = r->getMembers(); - for (const auto& member : members) - { - ConstElementPtr elm = map->getElement(member.getElementId()); - if (elm.get() == nullptr) - continue; - - if (firstRel) - firstRel = false; - else - _writer->writeCharacters(QString(", ")); - - // Sort out ways first. Nodes later - if (elm->getElementType() == ElementType::Way) - { - ConstWayPtr w = map->getWay(elm->getElementId()); - - _writer->writeCharacters(startBracket); - bool firstWay = true; - for (auto nid : w->getNodeIds()) - { - if (firstWay) - firstWay = false; - else - _writer->writeCharacters(QString(", ")); - - ConstNodePtr n = map->getNode(nid); - _writer->writeCharacters(QString("%1 %2").arg(QString::number(n->getX(), 'f', _precision), QString::number(n->getY(), 'f', _precision))); - } - _writer->writeCharacters(endBracket); - } // End way - - } // End relation member - - _writer->writeCharacters(QString(")")); - _writer->writeEndElement(); // WKT - - _writer->writeEndElement(); // geometry - - // Add the Det_id from the Tag - _writer->writeStartElement("id"); - _writer->writeCharacters(r->getTags()["Det_id"]); - _writer->writeEndElement(); - - _writer->writeEndElement(); // features - - _writer->writeEndElement(); // Det_Val - - _writeTags(r); - - _writer->writeEndElement(); -} - -void OsmGbdxXmlWriter::finalizePartial() -{ - // osmosis chokes on the bounds being written at the end of the file, so not writing it at all - close(); -} - -} diff --git a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.h b/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.h deleted file mode 100644 index 3367723a89..0000000000 --- a/hoot-core/src/main/cpp/hoot/core/io/OsmGbdxXmlWriter.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of Hootenanny. - * - * Hootenanny is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * -------------------------------------------------------------------- - * - * The following copyright notices are generated automatically. If you - * have a new notice to add, please use the format: - * " * @copyright Copyright ..." - * This will properly maintain the copyright information. Maxar - * copyrights will be updated automatically. - * - * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/) - */ -#ifndef OSMGBDXXMLWRITER_H -#define OSMGBDXXMLWRITER_H - -// hoot -#include - -// Qt -#include -#include - -namespace hoot -{ - -/** - * Writes an OsmMap to a GBDX XML format file. - */ -class OsmGbdxXmlWriter : public QXmlDefaultHandler, public PartialOsmMapWriter -{ -public: - - static QString className() { return "OsmGbdxXmlWriter"; } - - OsmGbdxXmlWriter(); - ~OsmGbdxXmlWriter() override; - - bool isSupported(const QString& url) const override { return url.endsWith(".gxml", Qt::CaseInsensitive); } - QString supportedFormats() const override { return ".gxml"; } - void open(const QString& url) override; - void close() override; - - /** - * Provided for backwards compatibility. Better to just use OsmMapWriterFactory::write() - */ - void write(const ConstOsmMapPtr& map, const QString& path); - void write(const ConstOsmMapPtr& map) override; - - void writePartial(const ConstNodePtr& node) override; - void writePartial(const ConstWayPtr& way) override; - void writePartial(const ConstRelationPtr& relation) override; - void finalizePartial() override; - - /** - * Write the map out to a string and return it. This is handy for debugging, but has obvious - * memory limitations with real data. - * - * @param map the map to write out as a string - * @param formatXml if true, formats the xml with indentations and new lines - * @return an OSM XML string - */ - static QString toString(const ConstOsmMapPtr& map, const bool formatXml = true); - - /** - * Remove any invalid characters from the string s and print an error if one is found. - */ - QString removeInvalidCharacters(const QString& s); - - bool getFormatXml() const { return _formatXml; } - - void setFormatXml(const bool format) { _formatXml = format; } - // Set the precision for writing coordinates - void setPrecision(int p) { _precision = p; } - -private: - - static int logWarnCount; - - bool _formatXml; - int _precision; - int _encodingErrorCount; - int _fileNumber; - - std::shared_ptr _fp; - std::shared_ptr _writer; - geos::geom::Envelope _bounds; - - static QString _typeName(ElementType e); - - /** - * @brief Close the open file and open a unique file for output - */ - void _newOutputFile(); - - QDir _outputDir; - QString _outputFileName; - - void _writeTags(const ConstElementPtr& element); - - void _writeNodes(ConstOsmMapPtr map); - - void _writeWays(ConstOsmMapPtr map); - void _writeWayWithPoints(const ConstWayPtr& w, ConstOsmMapPtr map); - - void _writeRelations(ConstOsmMapPtr map); - void _writeRelationWithPoints(const ConstRelationPtr& r, ConstOsmMapPtr map); - - /** - * @brief _writeBounds Writes out the OSM tag in the format: - * - * @param bounds the bounds to write - */ - void _writeBounds(const geos::geom::Envelope& bounds) const; -}; - -} - -#endif // OSMGBDXXMLWRITER_H