From 2c3a7c8bcc711cf34b79885edbf1e5dccacc5757 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 10 Dec 2019 14:36:07 +0100 Subject: ob_tran: restore traditional handling of +to_meter with pj_transform() and proj utility (fixes #1782) Fixes side-effect of https://github.com/OSGeo/PROJ/issues/1525 that went in 6.1.1 The correction is horribly hacky. Sorry... --- src/apps/proj.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/apps') diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 7fe08023..09c8a81d 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -490,6 +490,14 @@ int main(int argc, char **argv) { exit(0); } + // Ugly hack. See https://github.com/OSGeo/PROJ/issues/1782 + if( Proj->right == PJ_IO_UNITS_WHATEVER && Proj->descr && + strncmp(Proj->descr, "General Oblique Transformation", + strlen("General Oblique Transformation")) == 0 ) + { + Proj->right = PJ_IO_UNITS_PROJECTED; + } + if (inverse) { if (!Proj->inv) emess(3,"inverse projection not available"); -- cgit v1.2.3 From 46e28887e19e82488ff0659ff1f127c908fd4637 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 25 Dec 2019 10:11:01 +0100 Subject: projinfo: no longer call createBoundCRSToWGS84IfPossible() for WKT1:GDAL To align with GDAL 3.0.3 behaviour, no longer automatically try to create a boundCRS to WGS84 when exporting to WKT1:GDAL. The user has to explicitly specify --boundcrs-to-wgs84 if he wishes this behaviour. --- src/apps/projinfo.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/apps') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index fd9b2f46..c1139564 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -423,24 +423,13 @@ static void outputObject( std::cout << "WKT1:GDAL string:" << std::endl; } - auto crs = nn_dynamic_pointer_cast(obj); - std::shared_ptr objToExport; - if (crs) { - objToExport = nn_dynamic_pointer_cast( - crs->createBoundCRSToWGS84IfPossible( - dbContext, allowUseIntermediateCRS)); - } - if (!objToExport) { - objToExport = wktExportable; - } - auto formatter = WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL); if (outputOpt.singleLine) { formatter->setMultiLine(false); } formatter->setStrict(outputOpt.strict); - auto wkt = objToExport->exportToWKT(formatter.get()); + auto wkt = wktExportable->exportToWKT(formatter.get()); if (outputOpt.c_ify) { wkt = c_ify_string(wkt); } -- cgit v1.2.3 From 37da5e243191c04607597f6b8a77acfa017a5c99 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 25 Dec 2019 22:31:50 +0100 Subject: cct: revise end-of-line handling in logging, and always output debug and trace messages to stderr --- src/apps/cct.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/apps') diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index d29b58fb..cebf74da 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -161,19 +161,13 @@ static void logger(void *data, int level, const char *msg) { /* if we use PJ_LOG_NONE we always want to print stuff to stream */ if (level == PJ_LOG_NONE) { - fprintf(stream, "%s", msg); + fprintf(stream, "%s\n", msg); return; } - /* should always print to stderr if level == PJ_LOG_ERROR */ - if (level == PJ_LOG_ERROR) { - fprintf(stderr, "%s", msg); - return; - } - - /* otherwise only print if log level set by user is high enough */ - if (level <= log_tell) - fprintf(stream, "%s", msg); + /* otherwise only print if log level set by user is high enough or error */ + if (level <= log_tell || level == PJ_LOG_ERROR) + fprintf(stderr, "%s\n", msg); } FILE *fout; @@ -244,19 +238,19 @@ int main(int argc, char **argv) { proj_log_func (PJ_DEFAULT_CTX, (void *) fout, logger); if (opt_given (o, "version")) { - print (PJ_LOG_NONE, "%s: %s\n", o->progname, pj_get_release ()); + print (PJ_LOG_NONE, "%s: %s", o->progname, pj_get_release ()); return 0; } if (opt_given (o, "o")) fout = fopen (opt_arg (o, "output"), "wt"); if (nullptr==fout) { - print (PJ_LOG_ERROR, "%s: Cannot open '%s' for output\n", o->progname, opt_arg (o, "output")); + print (PJ_LOG_ERROR, "%s: Cannot open '%s' for output", o->progname, opt_arg (o, "output")); free (o); return 1; } - print (PJ_LOG_TRACE, "%s: Running in very verbose mode\n", o->progname); + print (PJ_LOG_TRACE, "%s: Running in very verbose mode", o->progname); if (opt_given (o, "z")) { fixed_z = proj_atof (opt_arg (o, "z")); @@ -287,7 +281,7 @@ int main(int argc, char **argv) { /* cppcheck-suppress invalidscanf */ ncols = sscanf (opt_arg (o, "c"), "%d,%d,%d,%d", columns_xyzt, columns_xyzt+1, columns_xyzt+2, columns_xyzt+3); if (ncols != nfields) { - print (PJ_LOG_ERROR, "%s: Too few input columns given: '%s'\n", o->progname, opt_arg (o, "c")); + print (PJ_LOG_ERROR, "%s: Too few input columns given: '%s'", o->progname, opt_arg (o, "c")); free (o); if (stdout != fout) fclose (fout); @@ -298,7 +292,7 @@ int main(int argc, char **argv) { /* Setup transformation */ P = proj_create_argv (nullptr, o->pargc, o->pargv); if ((nullptr==P) || (0==o->pargc)) { - print (PJ_LOG_ERROR, "%s: Bad transformation arguments - (%s)\n '%s -h' for help\n", + print (PJ_LOG_ERROR, "%s: Bad transformation arguments - (%s)\n '%s -h' for help", o->progname, pj_strerrno (proj_errno(P)), o->progname); free (o); if (stdout != fout) @@ -307,12 +301,12 @@ int main(int argc, char **argv) { } info = proj_pj_info (P); - print (PJ_LOG_TRACE, "Final: %s argc=%d pargc=%d\n", info.definition, argc, o->pargc); + print (PJ_LOG_TRACE, "Final: %s argc=%d pargc=%d", info.definition, argc, o->pargc); if (direction== PJ_INV) { /* fail if an inverse operation is not available */ if (!info.has_inverse) { - print (PJ_LOG_ERROR, "Inverse operation not available\n"); + print (PJ_LOG_ERROR, "Inverse operation not available"); if (stdout != fout) fclose (fout); return 1; @@ -325,7 +319,7 @@ int main(int argc, char **argv) { /* Allocate input buffer */ buf = static_cast(calloc (1, 10000)); if (nullptr==buf) { - print (PJ_LOG_ERROR, "%s: Out of memory\n", o->progname); + print (PJ_LOG_ERROR, "%s: Out of memory", o->progname); pj_free (P); free (o); if (stdout != fout) @@ -341,7 +335,7 @@ int main(int argc, char **argv) { char *c = column (buf, 1); opt_eof_handler (o); if (nullptr==ret) { - print (PJ_LOG_ERROR, "Read error in record %d\n", (int) o->record_index); + print (PJ_LOG_ERROR, "Read error in record %d", (int) o->record_index); continue; } point = parse_input_line (buf, columns_xyzt, fixed_z, fixed_time); @@ -359,7 +353,7 @@ int main(int argc, char **argv) { if (HUGE_VAL==point.xyzt.x) { /* otherwise, it must be a syntax error */ print (PJ_LOG_NONE, "# Record %d UNREADABLE: %s", (int) o->record_index, buf); - print (PJ_LOG_ERROR, "%s: Could not parse file '%s' line %d\n", o->progname, opt_filename (o), opt_record (o)); + print (PJ_LOG_ERROR, "%s: Could not parse file '%s' line %d", o->progname, opt_filename (o), opt_record (o)); continue; } @@ -395,7 +389,7 @@ int main(int argc, char **argv) { if (proj_angular_output (P, direction)) { point.lpzt.lam = proj_todeg (point.lpzt.lam); point.lpzt.phi = proj_todeg (point.lpzt.phi); - print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f%s%s\n", + print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f%s%s", decimals_angles, point.xyzt.x, decimals_angles, point.xyzt.y, decimals_distances, point.xyzt.z, @@ -403,7 +397,7 @@ int main(int argc, char **argv) { ); } else - print (PJ_LOG_NONE, "%13.*f %13.*f %12.*f %12.4f%s%s\n", + print (PJ_LOG_NONE, "%13.*f %13.*f %12.*f %12.4f%s%s", decimals_distances, point.xyzt.x, decimals_distances, point.xyzt.y, decimals_distances, point.xyzt.z, -- cgit v1.2.3 From d71a6ce9094daac790daf828e6148c99c30c3ed3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 25 Dec 2019 22:35:28 +0100 Subject: cct: make it honour PROJ_DEBUG if -v/-vv/-vvv are not specified --- src/apps/cct.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/apps') diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index cebf74da..f7413872 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -234,7 +234,9 @@ int main(int argc, char **argv) { PJ_DIRECTION direction = opt_given (o, "I")? PJ_INV: PJ_FWD; verbose = MIN(opt_given (o, "v"), 3); /* log level can't be larger than 3 */ - proj_log_level (PJ_DEFAULT_CTX, static_cast(verbose)); + if( verbose > 0 ) { + proj_log_level (PJ_DEFAULT_CTX, static_cast(verbose)); + } proj_log_func (PJ_DEFAULT_CTX, (void *) fout, logger); if (opt_given (o, "version")) { -- cgit v1.2.3 From 6426bcbd3605bf8cd6ae5c7869931fa89a26d641 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2020 15:32:47 +0100 Subject: projinfo: support -k datum --- src/apps/projinfo.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'src/apps') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index c1139564..09b17b31 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -78,7 +78,7 @@ struct OutputOptions { static void usage() { std::cerr - << "usage: projinfo [-o formats] [-k crs|operation|ellipsoid] " + << "usage: projinfo [-o formats] [-k crs|operation|datum|ellipsoid] " "[--summary] [-q]" << std::endl << " ([--area name_or_code] | " @@ -184,6 +184,9 @@ static BaseObjectNNPtr buildObject( } else if (kind == "ellipsoid" && tokens.size() == 2) { auto urn = "urn:ogc:def:ellipsoid:" + tokens[0] + "::" + tokens[1]; obj = createFromUserInput(urn, dbContext).as_nullable(); + } else if (kind == "datum" && tokens.size() == 2) { + auto urn = "urn:ogc:def:datum:" + tokens[0] + "::" + tokens[1]; + obj = createFromUserInput(urn, dbContext).as_nullable(); } else { // Convenience to be able to use C escaped strings... if (l_user_string.size() > 2 && l_user_string[0] == '"' && @@ -205,6 +208,59 @@ static BaseObjectNNPtr buildObject( } } } + } else if (dbContext && !kind.empty() && kind != "crs" && + l_user_string.find(':') == std::string::npos) { + std::vector allowedTypes; + if (kind == "operation") + allowedTypes.push_back( + AuthorityFactory::ObjectType::COORDINATE_OPERATION); + else if (kind == "ellipsoid") + allowedTypes.push_back( + AuthorityFactory::ObjectType::ELLIPSOID); + else if (kind == "datum") + allowedTypes.push_back(AuthorityFactory::ObjectType::DATUM); + constexpr size_t limitResultCount = 10; + auto factory = AuthorityFactory::create(NN_NO_CHECK(dbContext), + std::string()); + for (int pass = 0; pass <= 1; ++pass) { + const bool approximateMatch = (pass == 1); + auto res = factory->createObjectsFromName( + l_user_string, allowedTypes, approximateMatch, + limitResultCount); + if (res.size() == 1) { + obj = res.front().as_nullable(); + } else { + for (const auto &l_obj : res) { + if (Identifier::isEquivalentName( + l_obj->nameStr().c_str(), + l_user_string.c_str())) { + obj = l_obj.as_nullable(); + break; + } + } + if (obj) { + break; + } + } + if (res.size() > 1) { + std::string msg("several objects matching this name: "); + bool first = true; + for (const auto &l_obj : res) { + if (msg.size() > 200) { + msg += ", ..."; + break; + } + if (!first) { + msg += ", "; + } + first = false; + msg += l_obj->nameStr(); + } + std::cerr << context << ": " << msg << std::endl; + std::exit(1); + } + } + } else { obj = createFromUserInput(l_user_string, dbContext).as_nullable(); @@ -863,6 +919,8 @@ int main(int argc, char **argv) { objectKind = "operation"; } else if (ci_equal(kind, "ellipsoid")) { objectKind = "ellipsoid"; + } else if (ci_equal(kind, "datum")) { + objectKind = "datum"; } else { std::cerr << "Unrecognized value for option -k: " << kind << std::endl; -- cgit v1.2.3 From 18ba7b3dfcf1142227eacd8e76d4086a3d8292f4 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2020 21:38:05 +0100 Subject: projinfo: use No. abbreviation instead of UTF-8 character (fixes #1828) --- src/apps/projinfo.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/apps') diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index c1139564..8ce9eefe 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -686,9 +686,7 @@ static void outputOperations( } first = false; std::cout << "-------------------------------------" << std::endl; - std::cout << "Operation n" - "\xC2\xB0" - << (i + 1) << ":" << std::endl + std::cout << "Operation No. " << (i + 1) << ":" << std::endl << std::endl; outputOperationSummary(op, dbContext); std::cout << std::endl; -- cgit v1.2.3 From a955947c1f3279e51d1272df0cb6aa61ce4b85ee Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Mon, 13 Jan 2020 22:04:01 +0100 Subject: Remove -ld option from proj and cs2cs It promotes use of deprecated paramters +datum and +towgs84 which we don't want to encourage. Closes #1308 --- src/apps/cs2cs.cpp | 13 ------------- src/apps/proj.cpp | 11 ----------- 2 files changed, 24 deletions(-) (limited to 'src/apps') diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index 273233a7..6c85d4aa 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -430,19 +430,6 @@ int main(int argc, char **argv) { for (lu = proj_list_units(); lu->id; ++lu) (void)printf("%12s %-20s %s\n", lu->id, lu->to_meter, lu->name); - } else if (arg[1] == 'd') { /* list datums */ - const struct PJ_DATUMS *ld; - - printf("__datum_id__ __ellipse___ " - "__definition/" - "comments______________________________\n"); - for (ld = pj_get_datums_ref(); ld->id; ++ld) { - printf("%12s %-12s %-30s\n", ld->id, ld->ellipse_id, - ld->defn); - if (ld->comments != nullptr && - strlen(ld->comments) > 0) - printf("%25s %s\n", " ", ld->comments); - } } else if (arg[1] == 'm') { /* list prime meridians */ const struct PJ_PRIME_MERIDIANS *lpm; diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 09c8a81d..852cea04 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -385,17 +385,6 @@ int main(int argc, char **argv) { for (lu = proj_list_units(); lu->id ; ++lu) (void)printf("%12s %-20s %s\n", lu->id, lu->to_meter, lu->name); - } else if (arg[1] == 'd') { /* list datums */ - const struct PJ_DATUMS *ld; - - printf("__datum_id__ __ellipse___ __definition/comments______________________________\n" ); - for (ld = pj_get_datums_ref(); ld->id ; ++ld) - { - printf("%12s %-12s %-30s\n", - ld->id, ld->ellipse_id, ld->defn); - if( ld->comments != nullptr && strlen(ld->comments) > 0 ) - printf( "%25s %s\n", " ", ld->comments ); - } } else emess(1,"invalid list option: l%c",arg[1]); exit(0); -- cgit v1.2.3