aboutsummaryrefslogtreecommitdiff
path: root/src/apps/cs2cs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/apps/cs2cs.cpp')
-rw-r--r--src/apps/cs2cs.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp
index 150548c5..20e5e73c 100644
--- a/src/apps/cs2cs.cpp
+++ b/src/apps/cs2cs.cpp
@@ -45,6 +45,7 @@
#include "proj.h"
#include "proj_internal.h"
#include "emess.h"
+#include "utils.h"
// clang-format on
#define MAX_LINE 1000
@@ -68,8 +69,8 @@ static const char *oform =
static char oform_buffer[16]; /* buffer for oform when using -d */
static const char *oterr = "*\t*"; /* output line for unprojectable input */
static const char *usage =
- "%s\nusage: %s [ -dDeEfIlrstvwW [args] ] [ +opts[=arg] ]\n"
- " [+to [+opts[=arg] [ files ]\n";
+ "%s\nusage: %s [-dDeEfIlrstvwW [args]] [+opt[=arg] ...]\n"
+ " [+to +opt[=arg] ...] [file ...]\n";
static double (*informat)(const char *,
char **); /* input data deformatter function */
@@ -113,6 +114,19 @@ static void process(FILE *fid)
z = strtod(s, &s);
+ /* To avoid breaking existing tests, we read what is a possible t */
+ /* component of the input and rewind the s-pointer so that the final */
+ /* output has consistant behaviour, with or without t values. */
+ /* This is a bit of a hack, in most cases 4D coordinates will be */
+ /* written to STDOUT (except when using -E) but the output format */
+ /* speficied with -f is not respected for the t component, rather it */
+ /* is forward verbatim from the input. */
+ char *before_time = s;
+ double t = strtod(s, &s);
+ if( s == before_time )
+ t = HUGE_VAL;
+ s = before_time;
+
if (data.v == HUGE_VAL)
data.u = HUGE_VAL;
@@ -120,11 +134,11 @@ static void process(FILE *fid)
--s; /* assumed we gobbled \n */
if (echoin) {
- char t;
- t = *s;
+ char temp;
+ temp = *s;
*s = '\0';
(void)fputs(line, stdout);
- *s = t;
+ *s = temp;
putchar('\t');
}
@@ -141,7 +155,7 @@ static void process(FILE *fid)
coord.xyzt.x = data.u;
coord.xyzt.y = data.v;
coord.xyzt.z = z;
- coord.xyzt.t = HUGE_VAL;
+ coord.xyzt.t = t;
coord = proj_trans(transformation, PJ_FWD, coord);
data.u = coord.xyz.x;
data.v = coord.xyz.y;
@@ -206,10 +220,10 @@ static void process(FILE *fid)
}
/************************************************************************/
-/* instanciate_crs() */
+/* instantiate_crs() */
/************************************************************************/
-static PJ *instanciate_crs(const std::string &definition,
+static PJ *instantiate_crs(const std::string &definition,
bool &isGeog, double &toRadians,
bool &isLatFirst) {
PJ *crs = proj_create(nullptr,
@@ -263,13 +277,6 @@ static std::string get_geog_crs_proj_string_from_proj_crs(PJ *src,
double &toRadians,
bool &isLatFirst) {
auto srcType = proj_get_type(src);
- if (srcType == PJ_TYPE_BOUND_CRS) {
- auto base = proj_get_source_crs(nullptr, src);
- assert(base);
- proj_destroy(src);
- src = base;
- srcType = proj_get_type(src);
- }
if (srcType != PJ_TYPE_PROJECTED_CRS) {
return std::string();
}
@@ -518,6 +525,13 @@ int main(int argc, char **argv) {
if (eargc == 0) /* if no specific files force sysin */
eargv[eargc++] = const_cast<char *>("-");
+ if( oform ) {
+ if( !validate_form_string_for_numbers(oform) ) {
+ emess(3, "invalid format string");
+ exit(0);
+ }
+ }
+
/*
* If the user has requested inverse, then just reverse the
* coordinate systems.
@@ -541,7 +555,7 @@ int main(int argc, char **argv) {
PJ *src = nullptr;
if (!fromStr.empty()) {
bool ignored;
- src = instanciate_crs(fromStr, srcIsGeog,
+ src = instantiate_crs(fromStr, srcIsGeog,
srcToRadians, ignored);
if (!src) {
emess(3, "cannot instantiate source coordinate system");
@@ -550,7 +564,7 @@ int main(int argc, char **argv) {
PJ *dst = nullptr;
if (!toStr.empty()) {
- dst = instanciate_crs(toStr, destIsGeog,
+ dst = instantiate_crs(toStr, destIsGeog,
destToRadians, destIsLatLong);
if (!dst) {
emess(3, "cannot instantiate target coordinate system");