24 # pragma warning (disable: 4127)
27 #include "Planimeter.usage"
29 int main(
int argc,
char* argv[]) {
31 using namespace GeographicLib;
34 enum { GEODESIC, EXACT, AUTHALIC, RHUMB };
38 bool reverse =
false, sign =
true, polyline =
false;
39 int linetype = GEODESIC;
41 std::string istring, ifile, ofile, cdelim;
44 for (
int m = 1; m < argc; ++m) {
45 std::string arg(argv[m]);
52 else if (arg ==
"-e") {
53 if (m + 2 >= argc)
return usage(1,
true);
55 a = Utility::num<real>(std::string(argv[m + 1]));
56 f = Utility::fract<real>(std::string(argv[m + 2]));
58 catch (
const std::exception& e) {
59 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
63 }
else if (arg ==
"-p") {
64 if (++m == argc)
return usage(1,
true);
66 prec = Utility::num<int>(std::string(argv[m]));
68 catch (
const std::exception&) {
69 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
72 }
else if (arg ==
"-G")
80 else if (arg ==
"--input-string") {
81 if (++m == argc)
return usage(1,
true);
83 }
else if (arg ==
"--input-file") {
84 if (++m == argc)
return usage(1,
true);
86 }
else if (arg ==
"--output-file") {
87 if (++m == argc)
return usage(1,
true);
89 }
else if (arg ==
"--line-separator") {
90 if (++m == argc)
return usage(1,
true);
91 if (std::string(argv[m]).size() != 1) {
92 std::cerr <<
"Line separator must be a single character\n";
96 }
else if (arg ==
"--comment-delimiter") {
97 if (++m == argc)
return usage(1,
true);
99 }
else if (arg ==
"--version") {
100 std::cout << argv[0] <<
": GeographicLib version "
101 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
104 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
107 if (!ifile.empty() && !istring.empty()) {
108 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
111 if (ifile ==
"-") ifile.clear();
112 std::ifstream infile;
113 std::istringstream instring;
114 if (!ifile.empty()) {
115 infile.open(ifile.c_str());
116 if (!infile.is_open()) {
117 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
120 }
else if (!istring.empty()) {
121 std::string::size_type m = 0;
123 m = istring.find(lsep, m);
124 if (m == std::string::npos)
128 instring.str(istring);
130 std::istream* input = !ifile.empty() ? &infile :
131 (!istring.empty() ? &instring : &std::cin);
133 std::ofstream outfile;
134 if (ofile ==
"-") ofile.clear();
135 if (!ofile.empty()) {
136 outfile.open(ofile.c_str());
137 if (!outfile.is_open()) {
138 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
142 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
145 if (linetype == AUTHALIC) {
152 const Rhumb rhumb(a, f);
153 PolygonArea poly(geod, polyline);
154 PolygonAreaExact polye(geode, polyline);
155 PolygonAreaRhumb polyr(rhumb, polyline);
162 real perimeter, area;
164 std::string eol(
"\n");
165 while (std::getline(*input, s)) {
166 if (!cdelim.empty()) {
167 std::string::size_type m = s.find(cdelim);
168 if (m != std::string::npos) {
169 eol =
" " + s.substr(m) +
"\n";
173 bool endpoly = s.empty();
186 linetype == EXACT ? polye.Compute(reverse, sign, perimeter, area) :
187 linetype == RHUMB ? polyr.Compute(reverse, sign, perimeter, area) :
188 poly.Compute(reverse, sign, perimeter, area);
192 *output <<
" " <<
Utility::str(area, std::max(0, prec - 5));
196 linetype == EXACT ? polye.Clear() :
197 linetype == RHUMB ? polyr.Clear() : poly.Clear();
200 linetype == EXACT ? polye.AddPoint(p.Latitude(), p.Longitude()) :
201 linetype == RHUMB ? polyr.AddPoint(p.Latitude(), p.Longitude()) :
202 poly.AddPoint(linetype == AUTHALIC ?
209 linetype == EXACT ? polye.Compute(reverse, sign, perimeter, area) :
210 linetype == RHUMB ? polyr.Compute(reverse, sign, perimeter, area) :
211 poly.Compute(reverse, sign, perimeter, area);
215 *output <<
" " <<
Utility::str(area, std::max(0, prec - 5));
219 linetype == EXACT ? polye.Clear() :
220 linetype == RHUMB ? polyr.Clear() : poly.Clear();
224 catch (
const std::exception& e) {
225 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
229 std::cerr <<
"Caught unknown exception\n";
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Conversion between geographic coordinates.
Math::real AuthalicLatitude(real phi) const
Header for GeographicLib::GeoCoords class.
static int extra_digits()
static std::string str(T x, int p=-1)
Header for GeographicLib::Ellipsoid class.
int main(int argc, char *argv[])
static int set_digits(int ndigits=0)
Properties of an ellipsoid.
Exact geodesic calculations.
Header for GeographicLib::PolygonAreaT class.
Exception handling for GeographicLib.
Solve of the direct and inverse rhumb problems.
Header for GeographicLib::DMS class.