27 # pragma warning (disable: 4127 4701) 30 #include "TransverseMercatorProj.usage" 32 int main(
int argc,
char* argv[]) {
37 bool exact =
true, extended =
false, series =
false, reverse =
false;
44 std::string istring, ifile, ofile, cdelim;
47 for (
int m = 1; m < argc; ++m) {
48 std::string arg(argv[m]);
51 else if (arg ==
"-t") {
55 }
else if (arg ==
"-s") {
59 }
else if (arg ==
"-l") {
60 if (++m >= argc)
return usage(1,
true);
66 if (!(lon0 >= -540 && lon0 < 540))
70 catch (
const std::exception& e) {
71 std::cerr <<
"Error decoding argument of " << arg <<
": " 75 }
else if (arg ==
"-k") {
76 if (++m >= argc)
return usage(1,
true);
78 k0 = Utility::num<real>(std::string(argv[m]));
80 catch (
const std::exception& e) {
81 std::cerr <<
"Error decoding argument of " << arg <<
": " 85 }
else if (arg ==
"-e") {
86 if (m + 2 >= argc)
return usage(1,
true);
88 a = Utility::num<real>(std::string(argv[m + 1]));
89 f = Utility::fract<real>(std::string(argv[m + 2]));
91 catch (
const std::exception& e) {
92 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
96 }
else if (arg ==
"-p") {
97 if (++m == argc)
return usage(1,
true);
99 prec = Utility::num<int>(std::string(argv[m]));
101 catch (
const std::exception&) {
102 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
105 }
else if (arg ==
"--input-string") {
106 if (++m == argc)
return usage(1,
true);
108 }
else if (arg ==
"--input-file") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--output-file") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--line-separator") {
115 if (++m == argc)
return usage(1,
true);
116 if (std::string(argv[m]).size() != 1) {
117 std::cerr <<
"Line separator must be a single character\n";
121 }
else if (arg ==
"--comment-delimiter") {
122 if (++m == argc)
return usage(1,
true);
124 }
else if (arg ==
"--version") {
125 std::cout << argv[0] <<
": GeographicLib version " 126 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
129 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
132 if (!ifile.empty() && !istring.empty()) {
133 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
136 if (ifile ==
"-") ifile.clear();
137 std::ifstream infile;
138 std::istringstream instring;
139 if (!ifile.empty()) {
140 infile.open(ifile.c_str());
141 if (!infile.is_open()) {
142 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
145 }
else if (!istring.empty()) {
146 std::string::size_type m = 0;
148 m = istring.find(lsep, m);
149 if (m == std::string::npos)
153 instring.str(istring);
155 std::istream* input = !ifile.empty() ? &infile :
156 (!istring.empty() ? &instring : &std::cin);
158 std::ofstream outfile;
159 if (ofile ==
"-") ofile.clear();
160 if (!ofile.empty()) {
161 outfile.open(ofile.c_str());
162 if (!outfile.is_open()) {
163 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
167 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
174 : TransverseMercatorExact(1,
real(0.1), 1,
false);
181 std::cout << std::fixed;
182 while (std::getline(*input, s)) {
184 std::string eol(
"\n");
185 if (!cdelim.empty()) {
186 std::string::size_type m = s.find(cdelim);
187 if (m != std::string::npos) {
188 eol =
" " + s.substr(m) +
"\n";
192 std::istringstream str(s);
194 std::string stra, strb;
195 if (!(str >> stra >> strb))
198 x = Utility::num<real>(stra);
199 y = Utility::num<real>(strb);
208 TMS.
Reverse(lon0, x, y, lat, lon, gamma, k);
210 TME.
Reverse(lon0, x, y, lat, lon, gamma, k);
217 TMS.
Forward(lon0, lat, lon, x, y, gamma, k);
219 TME.
Forward(lon0, lat, lon, x, y, gamma, k);
226 catch (
const std::exception& e) {
227 *output <<
"ERROR: " << e.what() <<
"\n";
233 catch (
const std::exception& e) {
234 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
238 std::cerr <<
"Caught unknown exception\n";
static T AngNormalize(T x)
An exact implementation of the transverse Mercator projection.
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Header for GeographicLib::TransverseMercatorExact class.
Transverse Mercator projection.
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
Header for GeographicLib::TransverseMercator class.
int main(int argc, char *argv[])
static int extra_digits()
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
static Math::real Decode(const std::string &dms, flag &ind)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
Header for GeographicLib::EllipticFunction class.
static int set_digits(int ndigits=0)
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
Exception handling for GeographicLib.
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
Header for GeographicLib::DMS class.