From 872751c6734487bf1a222f2358678aa27ceeab4f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 30 Nov 2018 21:38:31 +0100 Subject: projinfo: add a --single-line option --- src/projinfo.cpp | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'src/projinfo.cpp') diff --git a/src/projinfo.cpp b/src/projinfo.cpp index dbbcdae2..8ed8e14a 100644 --- a/src/projinfo.cpp +++ b/src/projinfo.cpp @@ -65,6 +65,7 @@ struct OutputOptions { bool WKT1_GDAL = false; bool WKT1_ESRI = false; bool c_ify = false; + bool singleLine = false; }; // --------------------------------------------------------------------------- @@ -86,6 +87,7 @@ static void usage() { << " [--main-db-path path] [--aux-db-path path]*" << std::endl << " [--identify]" << std::endl + << " [--c-ify] [--single-line]" << std::endl << " {object_definition} | (-s {srs_def} -t {srs_def})" << std::endl; std::cerr << std::endl; @@ -263,9 +265,12 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (!outputOpt.quiet) { std::cout << "WKT2_2015 string: " << std::endl; } - auto wkt = wktExportable->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT2_2015) - .get()); + auto formatter = + WKTFormatter::create(WKTFormatter::Convention::WKT2_2015); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -285,10 +290,12 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (!outputOpt.quiet) { std::cout << "WKT2_2015_SIMPLIFIED string: " << std::endl; } - auto wkt = wktExportable->exportToWKT( - WKTFormatter::create( - WKTFormatter::Convention::WKT2_2015_SIMPLIFIED) - .get()); + auto formatter = WKTFormatter::create( + WKTFormatter::Convention::WKT2_2015_SIMPLIFIED); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -308,9 +315,12 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (!outputOpt.quiet) { std::cout << "WKT2_2018 string: " << std::endl; } - auto wkt = wktExportable->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT2_2018) - .get()); + auto formatter = + WKTFormatter::create(WKTFormatter::Convention::WKT2_2018); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -330,10 +340,12 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (!outputOpt.quiet) { std::cout << "WKT2_2018_SIMPLIFIED string: " << std::endl; } - auto wkt = wktExportable->exportToWKT( - WKTFormatter::create( - WKTFormatter::Convention::WKT2_2018_SIMPLIFIED) - .get()); + auto formatter = WKTFormatter::create( + WKTFormatter::Convention::WKT2_2018_SIMPLIFIED); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -364,9 +376,12 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, objToExport = wktExportable; } - auto wkt = objToExport->exportToWKT( - WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL) - .get()); + auto formatter = + WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL); + if (outputOpt.singleLine) { + formatter->setMultiLine(false); + } + auto wkt = objToExport->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } @@ -684,6 +699,8 @@ int main(int argc, char **argv) { outputOpt.quiet = true; } else if (arg == "--c-ify") { outputOpt.c_ify = true; + } else if (arg == "--single-line") { + outputOpt.singleLine = true; } else if (arg == "--summary") { summary = true; } else if (ci_equal(arg, "--boundcrs-to-wgs84")) { -- cgit v1.2.3 From c81ad96aa079aac30a4361df11a3ba51a7ac843a Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 1 Dec 2018 18:15:27 +0100 Subject: Add testing of projinfo utility --- src/projinfo.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/projinfo.cpp') diff --git a/src/projinfo.cpp b/src/projinfo.cpp index 8ed8e14a..7acb13af 100644 --- a/src/projinfo.cpp +++ b/src/projinfo.cpp @@ -206,7 +206,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (outputOpt.PROJ5) { try { if (!outputOpt.quiet) { - std::cout << "PROJ string: " << std::endl; + std::cout << "PROJ string:" << std::endl; } std::cout << projStringExportable->exportToPROJString( PROJStringFormatter::create( @@ -227,7 +227,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "PROJ.4 string: " << std::endl; + std::cout << "PROJ.4 string:" << std::endl; } auto crs = nn_dynamic_pointer_cast(obj); @@ -263,7 +263,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT2_2015 string: " << std::endl; + std::cout << "WKT2_2015 string:" << std::endl; } auto formatter = WKTFormatter::create(WKTFormatter::Convention::WKT2_2015); @@ -288,7 +288,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT2_2015_SIMPLIFIED string: " << std::endl; + std::cout << "WKT2_2015_SIMPLIFIED string:" << std::endl; } auto formatter = WKTFormatter::create( WKTFormatter::Convention::WKT2_2015_SIMPLIFIED); @@ -313,7 +313,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT2_2018 string: " << std::endl; + std::cout << "WKT2_2018 string:" << std::endl; } auto formatter = WKTFormatter::create(WKTFormatter::Convention::WKT2_2018); @@ -338,7 +338,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT2_2018_SIMPLIFIED string: " << std::endl; + std::cout << "WKT2_2018_SIMPLIFIED string:" << std::endl; } auto formatter = WKTFormatter::create( WKTFormatter::Convention::WKT2_2018_SIMPLIFIED); @@ -363,7 +363,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT1_GDAL: " << std::endl; + std::cout << "WKT1_GDAL:" << std::endl; } auto crs = nn_dynamic_pointer_cast(obj); @@ -400,7 +400,7 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::cout << std::endl; } if (!outputOpt.quiet) { - std::cout << "WKT1_ESRI: " << std::endl; + std::cout << "WKT1_ESRI:" << std::endl; } auto wkt = wktExportable->exportToWKT( @@ -586,6 +586,7 @@ int main(int argc, char **argv) { outputOpt.WKT2_2018 = true; outputOpt.WKT2_2015 = true; outputOpt.WKT1_GDAL = true; + outputOpt.WKT1_ESRI = true; } else if (ci_equal(format, "default")) { outputOpt.PROJ5 = true; outputOpt.PROJ4 = false; -- cgit v1.2.3