aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Holm <sgh@sgh.dk>2018-09-05 22:17:10 +0200
committerKristian Evers <kristianevers@gmail.com>2018-09-05 22:17:10 +0200
commitc11b98b058d883df6a0ef0a052ffd7565b00f921 (patch)
treef15a8c57306ab2a5bb7db062b6a793e0ed66b751
parent76488c5133207045f4bf9ccd3a9b4d0daf2372f5 (diff)
downloadPROJ-c11b98b058d883df6a0ef0a052ffd7565b00f921.tar.gz
PROJ-c11b98b058d883df6a0ef0a052ffd7565b00f921.zip
Add -d option to proj, cs2cs and cct (#1109)
Specify number of decimals to display when transforming coordinates with either proj, cs2cs or cct.
-rw-r--r--docs/source/apps/cct.rst4
-rw-r--r--docs/source/apps/cs2cs.rst4
-rw-r--r--docs/source/apps/proj.rst4
-rw-r--r--src/cct.c18
-rw-r--r--src/cs2cs.c10
-rw-r--r--src/proj.c10
6 files changed, 43 insertions, 7 deletions
diff --git a/docs/source/apps/cct.rst b/docs/source/apps/cct.rst
index b8f63cbb..f3130c78 100644
--- a/docs/source/apps/cct.rst
+++ b/docs/source/apps/cct.rst
@@ -32,6 +32,10 @@ The following control parameters can appear in any order:
Specify input columns for (up to) 4 input parameters. Defaults to 1,2,3,4.
+.. option:: -d<n>
+
+ Specify the number of decimals in the output. Applies to both angles and distances.
+
.. option:: -I
Do the inverse transformation.
diff --git a/docs/source/apps/cs2cs.rst b/docs/source/apps/cs2cs.rst
index 83b924a8..7871b281 100644
--- a/docs/source/apps/cs2cs.rst
+++ b/docs/source/apps/cs2cs.rst
@@ -36,6 +36,10 @@ The following control parameters can appear in any order:
line to be passed through without processing. This option applicable to
ASCII input only. (# is the default value).
+.. option:: -d<n>
+
+ Specify the number of decimals in the output. Applies to both angles and distances.
+
.. option:: -e <string>
Where *string* is an arbitrary string to be output if an error is detected during
diff --git a/docs/source/apps/proj.rst b/docs/source/apps/proj.rst
index 1eb11d3b..c81a230b 100644
--- a/docs/source/apps/proj.rst
+++ b/docs/source/apps/proj.rst
@@ -37,6 +37,10 @@ The following control parameters can appear in any order
floating point words. This option is to be used when :program:`proj` is a child process
and allows bypassing formatting operations.
+.. option:: -d<n>
+
+ Specify the number of decimals in the output. Applies to both angles and distances.
+
.. option:: -i
Selects binary input only (see :option:`-b`).
diff --git a/src/cct.c b/src/cct.c
index 13370ac2..7a53beeb 100644
--- a/src/cct.c
+++ b/src/cct.c
@@ -101,6 +101,7 @@ static const char usage[] = {
"--------------------------------------------------------------------------------\n"
" -c x,y,z,t Specify input columns for (up to) 4 input parameters.\n"
" Defaults to 1,2,3,4\n"
+ " -d n Specify number of decimals in output.\n"
" -I Do the inverse transformation\n"
" -o /path/to/file Specify output file name\n"
" -t value Provide a fixed t value for all input data (e.g. -t 0)\n"
@@ -113,6 +114,7 @@ static const char usage[] = {
"--------------------------------------------------------------------------------\n"
" --output Alias for -o\n"
" --columns Alias for -c\n"
+ " --decimals Alias for -d\n"
" --height Alias for -z\n"
" --time Alias for -t\n"
" --verbose Alias for -v\n"
@@ -207,11 +209,14 @@ int main(int argc, char **argv) {
char *buf;
int nfields = 4, direction = 1, skip_lines = 0, verbose;
double fixed_z = HUGE_VAL, fixed_time = HUGE_VAL;
+ int decimals_angles = 10;
+ int decimals_distances = 4;
int columns_xyzt[] = {1, 2, 3, 4};
const char *longflags[] = {"v=verbose", "h=help", "I=inverse", "version", 0};
const char *longkeys[] = {
"o=output",
"c=columns",
+ "d=decimals",
"z=height",
"t=time",
"s=skip-lines",
@@ -219,7 +224,7 @@ int main(int argc, char **argv) {
fout = stdout;
- o = opt_parse (argc, argv, "hvI", "cozts", longflags, longkeys);
+ o = opt_parse (argc, argv, "hvI", "cdozts", longflags, longkeys);
if (0==o)
return 0;
@@ -259,6 +264,13 @@ int main(int argc, char **argv) {
nfields--;
}
+ if (opt_given (o, "d")) {
+ int dec = atoi (opt_arg (o, "d"));
+ decimals_angles = dec;
+ decimals_distances = dec;
+ nfields--;
+ }
+
if (opt_given (o, "s")) {
skip_lines = atoi (opt_arg(o, "s"));
}
@@ -363,10 +375,10 @@ 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.10f %14.10f %12.4f %12.4f\n", point.xyzt.x, point.xyzt.y, point.xyzt.z, point.xyzt.t);
+ print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f\n", decimals_angles, point.xyzt.x, decimals_angles, point.xyzt.y, decimals_distances, point.xyzt.z, point.xyzt.t);
}
else
- print (PJ_LOG_NONE, "%13.4f %13.4f %12.4f %12.4f\n", point.xyzt.x, point.xyzt.y, point.xyzt.z, point.xyzt.t);
+ print (PJ_LOG_NONE, "%13.*f %13.*f %12.*f %12.4f\n", decimals_distances, point.xyzt.x, decimals_distances, point.xyzt.y, decimals_distances, point.xyzt.z, point.xyzt.t);
}
if (stdout != fout)
diff --git a/src/cs2cs.c b/src/cs2cs.c
index 167eafa3..76c47403 100644
--- a/src/cs2cs.c
+++ b/src/cs2cs.c
@@ -49,9 +49,10 @@ echoin = 0, /* echo input data to output line */
tag = '#'; /* beginning of line tag character */
static char
*oform = (char *)0, /* output format for x-y or decimal degrees */
+ oform_buffer[16], /* buffer for oform when using -d */
*oterr = "*\t*", /* output line for unprojectable input */
*usage =
-"%s\nusage: %s [ -eEfIlrstvwW [args] ] [ +opts[=arg] ]\n"
+"%s\nusage: %s [ -dDeEfIlrstvwW [args] ] [ +opts[=arg] ]\n"
" [+to [+opts[=arg] [ files ]\n";
static double (*informat)(const char *,
@@ -293,10 +294,15 @@ int main(int argc, char **argv)
case 's': /* reverse output */
reverseout = 1;
continue;
- case 'd': /* set debug level */
+ case 'D': /* set debug level */
if (--argc <= 0) goto noargument;
pj_ctx_set_debug( pj_get_default_ctx(), atoi(*++argv));
continue;
+ case 'd':
+ if (--argc <= 0) goto noargument;
+ sprintf(oform_buffer, "%%.%df", atoi(*++argv));
+ oform = oform_buffer;
+ break;
default:
emess(1, "invalid option: -%c",*arg);
break;
diff --git a/src/proj.c b/src/proj.c
index acd34da6..6fe579ee 100644
--- a/src/proj.c
+++ b/src/proj.c
@@ -45,11 +45,12 @@ static int
static char
*cheby_str, /* string controlling Chebychev evaluation */
- *oform = (char *)0; /* output format for x-y or decimal degrees */
+ *oform = (char *)0, /* output format for x-y or decimal degrees */
+ oform_buffer[16]; /* Buffer for oform when using -d */
static const char
*oterr = "*\t*", /* output line for unprojectable input */
- *usage = "%s\nusage: %s [ -beEfiIlmorsStTvVwW [args] ] [ +opts[=arg] ] [ files ]\n";
+ *usage = "%s\nusage: %s [ -bdeEfiIlmorsStTvVwW [args] ] [ +opts[=arg] ] [ files ]\n";
static struct FACTORS facs;
@@ -452,6 +453,11 @@ int main(int argc, char **argv) {
if (--argc <= 0) goto noargument;
oform = *++argv;
continue;
+ case 'd':
+ if (--argc <= 0) goto noargument;
+ sprintf(oform_buffer, "%%.%df", atoi(*++argv));
+ oform = oform_buffer;
+ break;
case 'r': /* reverse input */
reversein = 1;
continue;