38 # pragma warning (disable: 4127 4701)
41 #include "GeodesicProj.usage"
43 int main(
int argc,
char* argv[]) {
45 using namespace GeographicLib;
47 bool azimuthal =
false, cassini =
false, gnomonic =
false, reverse =
false;
48 real lat0 = 0, lon0 = 0;
50 a = Constants::WGS84_a<real>(),
51 f = Constants::WGS84_f<real>();
52 std::string istring, ifile, ofile, cdelim;
55 for (
int m = 1; m < argc; ++m) {
56 std::string arg(argv[m]);
59 else if (arg ==
"-c" || arg ==
"-z" || arg ==
"-g") {
60 cassini = arg ==
"-c";
61 azimuthal = arg ==
"-z";
62 gnomonic = arg ==
"-g";
63 if (m + 2 >= argc)
return usage(1,
true);
68 catch (
const std::exception& e) {
69 std::cerr <<
"Error decoding arguments of " << arg <<
": "
74 }
else if (arg ==
"-e") {
75 if (m + 2 >= argc)
return usage(1,
true);
77 a = Utility::num<real>(std::string(argv[m + 1]));
78 f = Utility::fract<real>(std::string(argv[m + 2]));
80 catch (
const std::exception& e) {
81 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
85 }
else if (arg ==
"--input-string") {
86 if (++m == argc)
return usage(1,
true);
88 }
else if (arg ==
"--input-file") {
89 if (++m == argc)
return usage(1,
true);
91 }
else if (arg ==
"--output-file") {
92 if (++m == argc)
return usage(1,
true);
94 }
else if (arg ==
"--line-separator") {
95 if (++m == argc)
return usage(1,
true);
96 if (std::string(argv[m]).size() != 1) {
97 std::cerr <<
"Line separator must be a single character\n";
101 }
else if (arg ==
"--comment-delimiter") {
102 if (++m == argc)
return usage(1,
true);
104 }
else if (arg ==
"--version") {
106 << argv[0] <<
": GeographicLib version "
107 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
110 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
113 if (!ifile.empty() && !istring.empty()) {
114 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
117 if (ifile ==
"-") ifile.clear();
118 std::ifstream infile;
119 std::istringstream instring;
120 if (!ifile.empty()) {
121 infile.open(ifile.c_str());
122 if (!infile.is_open()) {
123 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
126 }
else if (!istring.empty()) {
127 std::string::size_type m = 0;
129 m = istring.find(lsep, m);
130 if (m == std::string::npos)
134 instring.str(istring);
136 std::istream* input = !ifile.empty() ? &infile :
137 (!istring.empty() ? &instring : &std::cin);
139 std::ofstream outfile;
140 if (ofile ==
"-") ofile.clear();
141 if (!ofile.empty()) {
142 outfile.open(ofile.c_str());
143 if (!outfile.is_open()) {
144 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
148 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
150 if (!(azimuthal || cassini || gnomonic)) {
151 std::cerr <<
"Must specify \"-z lat0 lon0\" or "
152 <<
"\"-c lat0 lon0\" or \"-g lat0 lon0\"\n";
164 std::cout << std::fixed;
165 while (std::getline(*input, s)) {
167 std::string eol(
"\n");
168 if (!cdelim.empty()) {
169 std::string::size_type m = s.find(cdelim);
170 if (m != std::string::npos) {
171 eol =
" " + s.substr(m) +
"\n";
175 std::istringstream str(s);
176 real lat, lon, x, y, azi, rk;
177 std::string stra, strb;
178 if (!(str >> stra >> strb))
181 x = Utility::num<real>(stra);
182 y = Utility::num<real>(strb);
190 cs.Reverse(x, y, lat, lon, azi, rk);
192 az.
Reverse(lat0, lon0, x, y, lat, lon, azi, rk);
194 gn.
Reverse(lat0, lon0, x, y, lat, lon, azi, rk);
195 *output << Utility::str<real>(lat, 15) <<
" "
196 << Utility::str<real>(lon, 15) <<
" "
197 << Utility::str<real>(azi, 15) <<
" "
198 << Utility::str<real>(rk, 16) << eol;
201 cs.Forward(lat, lon, x, y, azi, rk);
203 az.
Forward(lat0, lon0, lat, lon, x, y, azi, rk);
205 gn.
Forward(lat0, lon0, lat, lon, x, y, azi, rk);
206 *output << Utility::str<real>(x, 10) <<
" "
207 << Utility::str<real>(y, 10) <<
" "
208 << Utility::str<real>(azi, 15) <<
" "
209 << Utility::str<real>(rk, 16) << eol;
212 catch (
const std::exception& e) {
213 *output <<
"ERROR: " << e.what() <<
"\n";
219 catch (
const std::exception& e) {
220 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
224 std::cerr <<
"Caught unknown exception\n";
Header for GeographicLib::CassiniSoldner class.
GeographicLib::Math::real real
void Reverse(real lat0, real lon0, real x, real y, real &lat, real &lon, real &azi, real &rk) const
int main(int argc, char *argv[])
Header for GeographicLib::Utility class.
Cassini-Soldner projection.
void Reverse(real lat0, real lon0, real x, real y, real &lat, real &lon, real &azi, real &rk) const
Header for GeographicLib::Gnomonic class.
Header for GeographicLib::Geodesic class.
Azimuthal equidistant projection.
static void DecodeLatLon(const std::string &dmsa, const std::string &dmsb, real &lat, real &lon, bool swaplatlong=false)
void Forward(real lat0, real lon0, real lat, real lon, real &x, real &y, real &azi, real &rk) const
void Forward(real lat0, real lon0, real lat, real lon, real &x, real &y, real &azi, real &rk) const
Exception handling for GeographicLib.
Header for GeographicLib::AzimuthalEquidistant class.
Header for GeographicLib::DMS class.