From ece151aed1b4bf2634de5759f37fd7bc005e8313 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 6 Jul 2019 17:06:23 +0200 Subject: CRS JSON: export GeographicCRS and Projected CRS --- src/apps/projinfo.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/apps/projinfo.cpp') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 9d724522..6b1267e0 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -67,6 +67,7 @@ struct OutputOptions { bool WKT2_2015_SIMPLIFIED = false; bool WKT1_GDAL = false; bool WKT1_ESRI = false; + bool JSON = false; bool c_ify = false; bool singleLine = false; bool strict = true; @@ -101,7 +102,7 @@ static void usage() { std::cerr << std::endl; std::cerr << "-o: formats is a comma separated combination of: " "all,default,PROJ,WKT_ALL,WKT2_2015,WKT2_2018,WKT1_GDAL," - "WKT1_ESRI" + "WKT1_ESRI,JSON" << std::endl; std::cerr << " Except 'all' and 'default', other format can be preceded " "by '-' to disable them" @@ -467,6 +468,29 @@ static void outputObject( std::cerr << "Error when exporting to WKT1_ESRI: " << e.what() << std::endl; } + alreadyOutputed = true; + } + } + + auto JSONExportable = nn_dynamic_pointer_cast(obj); + if (JSONExportable) { + if (outputOpt.JSON) { + try { + if (alreadyOutputed) { + std::cout << std::endl; + } + if (!outputOpt.quiet) { + std::cout << "JSON:" << std::endl; + } + + std::cout << JSONExportable->exportToJSON( + JSONFormatter::create(dbContext).get()) + << std::endl; + } catch (const std::exception &e) { + std::cerr << "Error when exporting to JSON: " << e.what() + << std::endl; + } + // alreadyOutputed = true; } } @@ -720,6 +744,7 @@ int main(int argc, char **argv) { outputOpt.WKT2_2015 = true; outputOpt.WKT1_GDAL = true; outputOpt.WKT1_ESRI = true; + outputOpt.JSON = true; } else if (ci_equal(format, "default")) { outputOpt.PROJ5 = true; outputOpt.WKT2_2018 = true; @@ -779,6 +804,10 @@ int main(int argc, char **argv) { ci_equal(format, "-WKT1-ESRI") || ci_equal(format, "-WKT1:ESRI")) { outputOpt.WKT1_ESRI = false; + } else if (ci_equal(format, "JSON")) { + outputOpt.JSON = true; + } else if (ci_equal(format, "-JSON")) { + outputOpt.JSON = false; } else { std::cerr << "Unrecognized value for option -o: " << format << std::endl; @@ -998,7 +1027,7 @@ int main(int argc, char **argv) { if (outputOpt.quiet && (outputOpt.PROJ5 + outputOpt.WKT2_2018 + outputOpt.WKT2_2015 + - outputOpt.WKT1_GDAL) != 1) { + outputOpt.WKT1_GDAL + outputOpt.JSON) != 1) { std::cerr << "-q can only be used with a single output format" << std::endl; usage(); -- cgit v1.2.3 From ec49c9cd0aa9de24623920b8de226daf05a0e90f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 8 Aug 2019 19:18:26 +0200 Subject: projinfo: rename JSON to PROJJSON --- src/apps/projinfo.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/apps/projinfo.cpp') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 6b1267e0..6cacdd66 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -67,7 +67,7 @@ struct OutputOptions { bool WKT2_2015_SIMPLIFIED = false; bool WKT1_GDAL = false; bool WKT1_ESRI = false; - bool JSON = false; + bool PROJJSON = false; bool c_ify = false; bool singleLine = false; bool strict = true; @@ -102,7 +102,7 @@ static void usage() { std::cerr << std::endl; std::cerr << "-o: formats is a comma separated combination of: " "all,default,PROJ,WKT_ALL,WKT2_2015,WKT2_2018,WKT1_GDAL," - "WKT1_ESRI,JSON" + "WKT1_ESRI,PROJJSON" << std::endl; std::cerr << " Except 'all' and 'default', other format can be preceded " "by '-' to disable them" @@ -474,20 +474,20 @@ static void outputObject( auto JSONExportable = nn_dynamic_pointer_cast(obj); if (JSONExportable) { - if (outputOpt.JSON) { + if (outputOpt.PROJJSON) { try { if (alreadyOutputed) { std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "JSON:" << std::endl; + std::cout << "PROJJSON:" << std::endl; } std::cout << JSONExportable->exportToJSON( JSONFormatter::create(dbContext).get()) << std::endl; } catch (const std::exception &e) { - std::cerr << "Error when exporting to JSON: " << e.what() + std::cerr << "Error when exporting to PROJJSON: " << e.what() << std::endl; } // alreadyOutputed = true; @@ -744,7 +744,7 @@ int main(int argc, char **argv) { outputOpt.WKT2_2015 = true; outputOpt.WKT1_GDAL = true; outputOpt.WKT1_ESRI = true; - outputOpt.JSON = true; + outputOpt.PROJJSON = true; } else if (ci_equal(format, "default")) { outputOpt.PROJ5 = true; outputOpt.WKT2_2018 = true; @@ -804,10 +804,10 @@ int main(int argc, char **argv) { ci_equal(format, "-WKT1-ESRI") || ci_equal(format, "-WKT1:ESRI")) { outputOpt.WKT1_ESRI = false; - } else if (ci_equal(format, "JSON")) { - outputOpt.JSON = true; - } else if (ci_equal(format, "-JSON")) { - outputOpt.JSON = false; + } else if (ci_equal(format, "PROJJSON")) { + outputOpt.PROJJSON = true; + } else if (ci_equal(format, "-PROJJSON")) { + outputOpt.PROJJSON = false; } else { std::cerr << "Unrecognized value for option -o: " << format << std::endl; @@ -1027,7 +1027,7 @@ int main(int argc, char **argv) { if (outputOpt.quiet && (outputOpt.PROJ5 + outputOpt.WKT2_2018 + outputOpt.WKT2_2015 + - outputOpt.WKT1_GDAL + outputOpt.JSON) != 1) { + outputOpt.WKT1_GDAL + outputOpt.PROJJSON) != 1) { std::cerr << "-q can only be used with a single output format" << std::endl; usage(); -- cgit v1.2.3 From 81bd57dfd8cfae609288643d1b09a4805f1bcded Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 9 Aug 2019 12:59:49 +0200 Subject: createFromUserInput(): add capability to import PROJJSON --- src/apps/projinfo.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/apps/projinfo.cpp') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 6cacdd66..8f3f09b8 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -482,10 +482,12 @@ static void outputObject( if (!outputOpt.quiet) { std::cout << "PROJJSON:" << std::endl; } - - std::cout << JSONExportable->exportToJSON( - JSONFormatter::create(dbContext).get()) - << std::endl; + auto jsonString(JSONExportable->exportToJSON( + JSONFormatter::create(dbContext).get())); + if (outputOpt.c_ify) { + jsonString = c_ify_string(jsonString); + } + std::cout << jsonString << std::endl; } catch (const std::exception &e) { std::cerr << "Error when exporting to PROJJSON: " << e.what() << std::endl; -- cgit v1.2.3 From 124eb228c464eaf170c03b70fd461fd1a06b82f2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 9 Aug 2019 17:26:47 +0200 Subject: projinfo: document PROJJSON output, and add single-line output capability --- src/apps/projinfo.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/apps/projinfo.cpp') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 8f3f09b8..1d75efa6 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -482,8 +482,11 @@ static void outputObject( if (!outputOpt.quiet) { std::cout << "PROJJSON:" << std::endl; } - auto jsonString(JSONExportable->exportToJSON( - JSONFormatter::create(dbContext).get())); + auto formatter(JSONFormatter::create(dbContext)); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto jsonString(JSONExportable->exportToJSON(formatter.get())); if (outputOpt.c_ify) { jsonString = c_ify_string(jsonString); } -- cgit v1.2.3