35 # pragma warning (disable: 4127 4701)
38 #include "TransverseMercatorProj.usage"
40 int main(
int argc,
char* argv[]) {
42 using namespace GeographicLib;
44 bool exact =
true, extended =
false, series =
false, reverse =
false;
46 a = Constants::WGS84_a<real>(),
47 f = Constants::WGS84_f<real>(),
48 k0 = Constants::UTM_k0<real>(),
50 std::string istring, ifile, ofile, cdelim;
53 for (
int m = 1; m < argc; ++m) {
54 std::string arg(argv[m]);
57 else if (arg ==
"-t") {
61 }
else if (arg ==
"-s") {
65 }
else if (arg ==
"-l") {
66 if (++m >= argc)
return usage(1,
true);
72 if (!(lon0 >= -540 && lon0 < 540))
76 catch (
const std::exception& e) {
77 std::cerr <<
"Error decoding argument of " << arg <<
": "
81 }
else if (arg ==
"-k") {
82 if (++m >= argc)
return usage(1,
true);
84 k0 = Utility::num<real>(std::string(argv[m]));
86 catch (
const std::exception& e) {
87 std::cerr <<
"Error decoding argument of " << arg <<
": "
91 }
else if (arg ==
"-e") {
92 if (m + 2 >= argc)
return usage(1,
true);
94 a = Utility::num<real>(std::string(argv[m + 1]));
95 f = Utility::fract<real>(std::string(argv[m + 2]));
97 catch (
const std::exception& e) {
98 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
102 }
else if (arg ==
"--input-string") {
103 if (++m == argc)
return usage(1,
true);
105 }
else if (arg ==
"--input-file") {
106 if (++m == argc)
return usage(1,
true);
108 }
else if (arg ==
"--output-file") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--line-separator") {
112 if (++m == argc)
return usage(1,
true);
113 if (std::string(argv[m]).size() != 1) {
114 std::cerr <<
"Line separator must be a single character\n";
118 }
else if (arg ==
"--comment-delimiter") {
119 if (++m == argc)
return usage(1,
true);
121 }
else if (arg ==
"--version") {
123 << argv[0] <<
": GeographicLib version "
124 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
127 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
130 if (!ifile.empty() && !istring.empty()) {
131 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
134 if (ifile ==
"-") ifile.clear();
135 std::ifstream infile;
136 std::istringstream instring;
137 if (!ifile.empty()) {
138 infile.open(ifile.c_str());
139 if (!infile.is_open()) {
140 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
143 }
else if (!istring.empty()) {
144 std::string::size_type m = 0;
146 m = istring.find(lsep, m);
147 if (m == std::string::npos)
151 instring.str(istring);
153 std::istream* input = !ifile.empty() ? &infile :
154 (!istring.empty() ? &instring : &std::cin);
156 std::ofstream outfile;
157 if (ofile ==
"-") ofile.clear();
158 if (!ofile.empty()) {
159 outfile.open(ofile.c_str());
160 if (!outfile.is_open()) {
161 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
165 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
172 : TransverseMercatorExact(1,
real(0.1), 1,
false);
176 std::cout << std::fixed;
177 while (std::getline(*input, s)) {
179 std::string eol(
"\n");
180 if (!cdelim.empty()) {
181 std::string::size_type m = s.find(cdelim);
182 if (m != std::string::npos) {
183 eol =
" " + s.substr(m) +
"\n";
187 std::istringstream str(s);
189 std::string stra, strb;
190 if (!(str >> stra >> strb))
193 x = Utility::num<real>(stra);
194 y = Utility::num<real>(strb);
203 TMS.Reverse(lon0, x, y, lat, lon, gamma, k);
205 TME.Reverse(lon0, x, y, lat, lon, gamma, k);
206 *output << Utility::str<real>(lat, 15) <<
" "
207 << Utility::str<real>(lon, 15) <<
" "
208 << Utility::str<real>(gamma, 16) <<
" "
209 << Utility::str<real>(k, 16) << eol;
212 TMS.Forward(lon0, lat, lon, x, y, gamma, k);
214 TME.Forward(lon0, lat, lon, x, y, gamma, k);
215 *output << Utility::str<real>(x, 10) <<
" "
216 << Utility::str<real>(y, 10) <<
" "
217 << Utility::str<real>(gamma, 16) <<
" "
218 << Utility::str<real>(k, 16) << eol;
221 catch (
const std::exception& e) {
222 *output <<
"ERROR: " << e.what() <<
"\n";
228 catch (
const std::exception& e) {
229 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
233 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.
Header for GeographicLib::TransverseMercator class.
int main(int argc, char *argv[])
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
static Math::real Decode(const std::string &dms, flag &ind)
Header for GeographicLib::EllipticFunction class.
Exception handling for GeographicLib.
Header for GeographicLib::DMS class.