diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-17 00:24:03 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-01-17 00:52:19 +0100 |
| commit | 4724025e6c817761052fc0dc8810fd489a9e0104 (patch) | |
| tree | 21117e52f95b8f36880efef8cd71c1fcec21242c /src/apps | |
| parent | 66fd99a8831955034cb25c8468ecfe1f9d3a7d62 (diff) | |
| parent | d76e6202d27c730b4dcbf16b8c1575c11b703485 (diff) | |
| download | PROJ-4724025e6c817761052fc0dc8810fd489a9e0104.tar.gz PROJ-4724025e6c817761052fc0dc8810fd489a9e0104.zip | |
Merge branch 'master' into rfc4_merge_back_master
Diffstat (limited to 'src/apps')
| -rw-r--r-- | src/apps/cct.cpp | 42 | ||||
| -rw-r--r-- | src/apps/cs2cs.cpp | 13 | ||||
| -rw-r--r-- | src/apps/gie.cpp | 1 | ||||
| -rw-r--r-- | src/apps/proj.cpp | 19 | ||||
| -rw-r--r-- | src/apps/projinfo.cpp | 77 |
5 files changed, 89 insertions, 63 deletions
diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index d29b58fb..f7413872 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; @@ -240,23 +234,25 @@ 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<PJ_LOG_LEVEL>(verbose)); + if( verbose > 0 ) { + proj_log_level (PJ_DEFAULT_CTX, static_cast<PJ_LOG_LEVEL>(verbose)); + } 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 +283,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 +294,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 +303,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 +321,7 @@ int main(int argc, char **argv) { /* Allocate input buffer */ buf = static_cast<char*>(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 +337,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 +355,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 +391,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 +399,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, 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/gie.cpp b/src/apps/gie.cpp index 6a67b55d..d9907776 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -1153,6 +1153,7 @@ static const struct errno_vs_err_const lookup[] = { {"pjd_err_inconsistent_unit" , -59}, {"pjd_err_mutually_exclusive_args" , -60}, {"pjd_err_generic_error" , -61}, + {"pjd_err_network_error" , -62}, {"pjd_err_dont_skip" , 5555}, {"pjd_err_unknown" , 9999}, {"pjd_err_enomem" , ENOMEM}, diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 7fe08023..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); @@ -490,6 +479,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"); diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index f13e526b..27ea278a 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] | " @@ -185,6 +185,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] == '"' && @@ -206,6 +209,59 @@ static BaseObjectNNPtr buildObject( } } } + } else if (dbContext && !kind.empty() && kind != "crs" && + l_user_string.find(':') == std::string::npos) { + std::vector<AuthorityFactory::ObjectType> 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(); @@ -424,24 +480,13 @@ static void outputObject( std::cout << "WKT1:GDAL string:" << std::endl; } - auto crs = nn_dynamic_pointer_cast<CRS>(obj); - std::shared_ptr<IWKTExportable> objToExport; - if (crs) { - objToExport = nn_dynamic_pointer_cast<IWKTExportable>( - 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); } @@ -706,9 +751,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, gridAvailabilityUse); std::cout << std::endl; @@ -885,6 +928,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; |
