Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output with roman numerals in cs2cs for lat-lon #4242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 69 additions & 5 deletions src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static bool destIsLongLat = false;
static double destToRadians = 0.0;
static bool destIsLatLong = false;

static bool romanNumerals = false;

static int reversein = 0, /* != 0 reverse input arguments */
reverseout = 0, /* != 0 reverse output arguments */
echoin = 0, /* echo input data to output line */
Expand Down Expand Up @@ -94,6 +96,54 @@ using namespace NS_PROJ::metadata;
using namespace NS_PROJ::util;
using namespace NS_PROJ::internal;

static std::string degToRoman(double angle, const std::string &pos,
const std::string &neg) {
const std::string sign = angle > 0.0 ? pos : neg;
angle = fabs(angle);
double r = angle;
r = floor(r * 3600 + .0005);
int sec = (int)fmod(r, 60.);
r = floor(r / 60.);
int min = (int)fmod(r, 60.);
r = floor(r / 60.);
int deg = (int)r;

auto intToRoman = [](int i) {
int unit = i % 10;
int tenth = i / 10 % 10;
int houndr = i / 100 % 10;
auto oneDigit = [](int digit, const std::string &one,
const std::string &five, const std::string &ten) {
switch (digit) {
case (1):
return one;
case (2):
return one + one;
case (3):
return one + one + one;
case (4):
return one + five;
case (5):
return five;
case (6):
return five + one;
case (7):
return five + one + one;
case (8):
return five + one + one + one;
case (9):
return one + ten;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhmmm, I do not now if it is a flaw, or a feature. It was implemented in a way that 0 uses no-symbol. It would be strange something like d9'12"M , o even d'"S d'"OC for null island. But at the same time I like it even more, because it shows how roman numerals work (or not work).

return std::string{};
}
};
return oneDigit(houndr, "C", "D", "M") +
oneDigit(tenth, "X", "L", "C") + oneDigit(unit, "I", "V", "X");
};
return intToRoman(deg) + "d" + intToRoman(min) + "'" + intToRoman(sec) +
"\"" + sign;
}

/************************************************************************/
/* process() */
/* */
Expand Down Expand Up @@ -208,11 +258,21 @@ static void process(FILE *fid)
fputs(rtodms(pline, sizeof(pline), data.u, 'N', 'S'),
stdout);
} else {
fputs(rtodms(pline, sizeof(pline), data.u, 'N', 'S'),
stdout);
putchar('\t');
fputs(rtodms(pline, sizeof(pline), data.v, 'E', 'W'),
stdout);
if (romanNumerals) {
std::string ns =
(degToRoman(data.u * RAD_TO_DEG, "S", "M"));
std::string ew =
(degToRoman(data.v * RAD_TO_DEG, "OR", "OC"));
fputs(ns.c_str(), stdout);
putchar('\t');
fputs(ew.c_str(), stdout);
} else {
fputs(rtodms(pline, sizeof(pline), data.u, 'N', 'S'),
stdout);
putchar('\t');
fputs(rtodms(pline, sizeof(pline), data.v, 'E', 'W'),
stdout);
}
}
} else if (reverseout) {
fputs(rtodms(pline, sizeof(pline), data.v, 'N', 'S'), stdout);
Expand Down Expand Up @@ -506,6 +566,10 @@ int main(int argc, char **argv) {
std::exit(1);
}
targetEpoch = *argv;
} else if (strcmp(*argv, "--roman") == 0) {
++argv;
--argc;
romanNumerals = true;
} else if (**argv == '-') {
for (arg = *argv;;) {
switch (*++arg) {
Expand Down
8 changes: 8 additions & 0 deletions test/cli/test_cs2cs_various.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,3 +1505,11 @@ tests:
in: 16.248285304 -61.484212843 53.073
out: |
661991.318 1796999.201 93.846
- comment: Test --roman
args: EPSG:4326 EPSG:10606 --roman
in: |
45d8'47.014"N 1d53'20.681"E 0.000
49d28'26.014"S 4d6'18.281"W 0.000
out: |
XLVdVIII'XLVII"S IdLIII'XX"OR 0.000
XLIXdXXVIII'XXVI"M IVdVI'XVIII"OC 0.000