aboutsummaryrefslogtreecommitdiff
path: root/src/iso19111/io.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-10-18 18:42:31 +0200
committerGitHub <noreply@github.com>2020-10-18 18:42:31 +0200
commit2357d264d477c5eee363514fb094772980509726 (patch)
treec4bdcbe7d36d961a9a55241844fe1977d3434aad /src/iso19111/io.cpp
parent3a2df3462c851b7dc823b1cd84fc8a61dc9c2d08 (diff)
parentffe1922d54d4ce379c96f5472dba2e76223348f1 (diff)
downloadPROJ-2357d264d477c5eee363514fb094772980509726.tar.gz
PROJ-2357d264d477c5eee363514fb094772980509726.zip
Merge pull request #2381 from rouault/fix_1453
Add multi-line PROJ string export capability, and use it by default in projinfo (unless --single-line is specified) (fixes #1543)
Diffstat (limited to 'src/iso19111/io.cpp')
-rw-r--r--src/iso19111/io.cpp78
1 files changed, 70 insertions, 8 deletions
diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp
index c464b724..7a107f96 100644
--- a/src/iso19111/io.cpp
+++ b/src/iso19111/io.cpp
@@ -6722,6 +6722,10 @@ struct PROJStringFormatter::Private {
bool coordOperationOptimizations_ = false;
bool crsExport_ = false;
bool legacyCRSToCRSContext_ = false;
+ bool multiLine_ = false;
+ int indentWidth_ = 2;
+ int indentLevel_ = 0;
+ int maxLineLength_ = 80;
std::string result_{};
@@ -6780,6 +6784,36 @@ void PROJStringFormatter::setUseApproxTMerc(bool flag) {
// ---------------------------------------------------------------------------
+/** \brief Whether to use multi line output or not. */
+PROJStringFormatter &
+PROJStringFormatter::setMultiLine(bool multiLine) noexcept {
+ d->multiLine_ = multiLine;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+/** \brief Set number of spaces for each indentation level (defaults to 2).
+ */
+PROJStringFormatter &
+PROJStringFormatter::setIndentationWidth(int width) noexcept {
+ d->indentWidth_ = width;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+/** \brief Set the maximum size of a line (when multiline output is enable).
+ * Can be set to 0 for unlimited length.
+ */
+PROJStringFormatter &
+PROJStringFormatter::setMaxLineLength(int maxLineLength) noexcept {
+ d->maxLineLength_ = maxLineLength;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
/** \brief Returns the PROJ string. */
const std::string &PROJStringFormatter::toString() const {
@@ -7308,28 +7342,56 @@ const std::string &PROJStringFormatter::toString() const {
pj_double_quote_string_param_if_needed(paramValue.value);
}
}
+
+ if (d->multiLine_) {
+ d->indentLevel_++;
+ }
}
for (const auto &step : d->steps_) {
+ std::string curLine;
if (!d->result_.empty()) {
- d->appendToResult("+step");
+ if (d->multiLine_) {
+ curLine = std::string(d->indentLevel_ * d->indentWidth_, ' ');
+ curLine += "+step";
+ } else {
+ curLine = " +step";
+ }
}
if (step.inverted) {
- d->appendToResult("+inv");
+ curLine += " +inv";
}
if (!step.name.empty()) {
- d->appendToResult(step.isInit ? "+init=" : "+proj=");
- d->result_ += step.name;
+ if (!curLine.empty())
+ curLine += ' ';
+ curLine += step.isInit ? "+init=" : "+proj=";
+ curLine += step.name;
}
for (const auto &paramValue : step.paramValues) {
- d->appendToResult("+");
- d->result_ += paramValue.key;
+ std::string newKV = "+";
+ newKV += paramValue.key;
if (!paramValue.value.empty()) {
- d->result_ += '=';
- d->result_ +=
+ newKV += '=';
+ newKV +=
pj_double_quote_string_param_if_needed(paramValue.value);
}
+ if (d->maxLineLength_ > 0 && d->multiLine_ &&
+ curLine.size() + newKV.size() >
+ static_cast<size_t>(d->maxLineLength_)) {
+ if (d->multiLine_ && !d->result_.empty())
+ d->result_ += '\n';
+ d->result_ += curLine;
+ curLine = std::string(
+ d->indentLevel_ * d->indentWidth_ + strlen("+step "), ' ');
+ } else {
+ if (!curLine.empty())
+ curLine += ' ';
+ }
+ curLine += newKV;
}
+ if (d->multiLine_ && !d->result_.empty())
+ d->result_ += '\n';
+ d->result_ += curLine;
}
if (d->result_.empty()) {