33 # pragma warning (disable: 4127 4701)
36 #include "ConicProj.usage"
38 int main(
int argc,
char* argv[]) {
40 using namespace GeographicLib;
42 bool lcc =
false, albers =
false, reverse =
false;
43 real lat1 = 0, lat2 = 0, lon0 = 0, k1 = 1;
45 a = Constants::WGS84_a<real>(),
46 f = Constants::WGS84_f<real>();
47 std::string istring, ifile, ofile, cdelim;
50 for (
int m = 1; m < argc; ++m) {
51 std::string arg(argv[m]);
54 else if (arg ==
"-c" || arg ==
"-a") {
57 if (m + 2 >= argc)
return usage(1,
true);
59 for (
int i = 0; i < 2; ++i) {
61 (i ? lat2 : lat1) =
DMS::Decode(std::string(argv[++m]), ind);
66 catch (
const std::exception& e) {
67 std::cerr <<
"Error decoding arguments of " << arg <<
": "
71 }
else if (arg ==
"-l") {
72 if (++m == argc)
return usage(1,
true);
78 if (!(lon0 >= -540 && lon0 < 540))
82 catch (
const std::exception& e) {
83 std::cerr <<
"Error decoding argument of " << arg <<
": "
87 }
else if (arg ==
"-k") {
88 if (++m == argc)
return usage(1,
true);
90 k1 = Utility::num<real>(std::string(argv[m]));
92 catch (
const std::exception& e) {
93 std::cerr <<
"Error decoding argument of " << arg <<
": "
97 }
else if (arg ==
"-e") {
98 if (m + 2 >= argc)
return usage(1,
true);
100 a = Utility::num<real>(std::string(argv[m + 1]));
101 f = Utility::fract<real>(std::string(argv[m + 2]));
103 catch (
const std::exception& e) {
104 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
108 }
else if (arg ==
"--input-string") {
109 if (++m == argc)
return usage(1,
true);
111 }
else if (arg ==
"--input-file") {
112 if (++m == argc)
return usage(1,
true);
114 }
else if (arg ==
"--output-file") {
115 if (++m == argc)
return usage(1,
true);
117 }
else if (arg ==
"--line-separator") {
118 if (++m == argc)
return usage(1,
true);
119 if (std::string(argv[m]).size() != 1) {
120 std::cerr <<
"Line separator must be a single character\n";
124 }
else if (arg ==
"--comment-delimiter") {
125 if (++m == argc)
return usage(1,
true);
127 }
else if (arg ==
"--version") {
129 << argv[0] <<
": GeographicLib version "
130 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
133 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
136 if (!ifile.empty() && !istring.empty()) {
137 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
140 if (ifile ==
"-") ifile.clear();
141 std::ifstream infile;
142 std::istringstream instring;
143 if (!ifile.empty()) {
144 infile.open(ifile.c_str());
145 if (!infile.is_open()) {
146 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
149 }
else if (!istring.empty()) {
150 std::string::size_type m = 0;
152 m = istring.find(lsep, m);
153 if (m == std::string::npos)
157 instring.str(istring);
159 std::istream* input = !ifile.empty() ? &infile :
160 (!istring.empty() ? &instring : &std::cin);
162 std::ofstream outfile;
163 if (ofile ==
"-") ofile.clear();
164 if (!ofile.empty()) {
165 outfile.open(ofile.c_str());
166 if (!outfile.is_open()) {
167 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
171 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
173 if (!(lcc || albers)) {
174 std::cerr <<
"Must specify \"-c lat1 lat2\" or "
175 <<
"\"-a lat1 lat2\"\n";
181 : LambertConformalConic(1, 0, 0, 0, 1);
184 : AlbersEqualArea(1, 0, 0, 0, 1);
188 std::cout << std::fixed;
189 while (std::getline(*input, s)) {
191 std::string eol(
"\n");
192 if (!cdelim.empty()) {
193 std::string::size_type m = s.find(cdelim);
194 if (m != std::string::npos) {
195 eol =
" " + s.substr(m) +
"\n";
199 std::istringstream str(s);
200 real lat, lon, x, y, gamma, k;
201 std::string stra, strb;
202 if (!(str >> stra >> strb))
205 x = Utility::num<real>(stra);
206 y = Utility::num<real>(strb);
214 lproj.Reverse(lon0, x, y, lat, lon, gamma, k);
216 aproj.Reverse(lon0, x, y, lat, lon, gamma, k);
217 *output << Utility::str<real>(lat, 15) <<
" "
218 << Utility::str<real>(lon, 15) <<
" "
219 << Utility::str<real>(gamma, 16) <<
" "
220 << Utility::str<real>(k, 16) << eol;
223 lproj.Forward(lon0, lat, lon, x, y, gamma, k);
225 aproj.Forward(lon0, lat, lon, x, y, gamma, k);
226 *output << Utility::str<real>(x, 10) <<
" "
227 << Utility::str<real>(y, 10) <<
" "
228 << Utility::str<real>(gamma, 16) <<
" "
229 << Utility::str<real>(k, 16) << eol;
232 catch (
const std::exception& e) {
233 *output <<
"ERROR: " << e.what() <<
"\n";
239 catch (
const std::exception& e) {
240 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
244 std::cerr <<
"Caught unknown exception\n";
static T AngNormalize(T x)
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Header for GeographicLib::AlbersEqualArea class.
Albers equal area conic projection.
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)
int main(int argc, char *argv[])
Exception handling for GeographicLib.
Header for GeographicLib::DMS class.