38 # pragma warning (disable: 4127)
41 #include "Planimeter.usage"
43 int main(
int argc,
char* argv[]) {
51 bool reverse =
false, sign =
true, polyline =
false,
52 exact =
false, authalic =
false;
54 std::string istring, ifile, ofile, cdelim;
57 for (
int m = 1; m < argc; ++m) {
58 std::string arg(argv[m]);
65 else if (arg ==
"-e") {
66 if (m + 2 >= argc)
return usage(1,
true);
68 a = Utility::num<real>(std::string(argv[m + 1]));
69 f = Utility::fract<real>(std::string(argv[m + 2]));
71 catch (
const std::exception& e) {
72 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
76 }
else if (arg ==
"-p") {
77 if (++m == argc)
return usage(1,
true);
79 prec = Utility::num<int>(std::string(argv[m]));
81 catch (
const std::exception&) {
82 std::cerr <<
"Precision " << argv[m] <<
" is not a number\n";
85 }
else if (arg ==
"-E") {
88 }
else if (arg ==
"-Q") {
91 }
else if (arg ==
"--input-string") {
92 if (++m == argc)
return usage(1,
true);
94 }
else if (arg ==
"--input-file") {
95 if (++m == argc)
return usage(1,
true);
97 }
else if (arg ==
"--output-file") {
98 if (++m == argc)
return usage(1,
true);
100 }
else if (arg ==
"--line-separator") {
101 if (++m == argc)
return usage(1,
true);
102 if (std::string(argv[m]).size() != 1) {
103 std::cerr <<
"Line separator must be a single character\n";
107 }
else if (arg ==
"--comment-delimiter") {
108 if (++m == argc)
return usage(1,
true);
110 }
else if (arg ==
"--version") {
112 << argv[0] <<
": GeographicLib version "
113 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
116 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
119 if (!ifile.empty() && !istring.empty()) {
120 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
123 if (ifile ==
"-") ifile.clear();
124 std::ifstream infile;
125 std::istringstream instring;
126 if (!ifile.empty()) {
127 infile.open(ifile.c_str());
128 if (!infile.is_open()) {
129 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
132 }
else if (!istring.empty()) {
133 std::string::size_type m = 0;
135 m = istring.find(lsep, m);
136 if (m == std::string::npos)
140 instring.str(istring);
142 std::istream* input = !ifile.empty() ? &infile :
143 (!istring.empty() ? &instring : &std::cin);
145 std::ofstream outfile;
146 if (ofile ==
"-") ofile.clear();
147 if (!ofile.empty()) {
148 outfile.open(ofile.c_str());
149 if (!outfile.is_open()) {
150 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
154 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
164 PolygonArea poly(geod, polyline);
165 PolygonAreaExact polye(geode, polyline);
172 real perimeter, area;
174 std::string eol(
"\n");
175 while (std::getline(*input, s)) {
176 if (!cdelim.empty()) {
177 std::string::size_type m = s.find(cdelim);
178 if (m != std::string::npos) {
179 eol =
" " + s.substr(m) +
"\n";
183 bool endpoly = s.empty();
195 num = exact ? polye.Compute(reverse, sign, perimeter, area) :
196 poly.Compute(reverse, sign, perimeter, area);
200 *output <<
" " <<
Utility::str(area, std::max(0, prec - 5));
204 exact ? polye.Clear() : poly.Clear();
213 num = exact ? polye.Compute(reverse, sign, perimeter, area):
214 poly.Compute(reverse, sign, perimeter, area);
218 *output <<
" " <<
Utility::str(area, std::max(0, prec - 5));
222 exact ? polye.Clear() : poly.Clear();
226 catch (
const std::exception& e) {
227 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
231 std::cerr <<
"Caught unknown exception\n";
Math::real Latitude() const
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
int main(int argc, char *argv[])
Conversion between geographic coordinates.
Math::real AuthalicLatitude(real phi) const
Header for GeographicLib::GeoCoords class.
static int extra_digits()
void Reset(const std::string &s, bool centerp=true, bool swaplatlong=false)
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
Header for GeographicLib::Ellipsoid class.
static int set_digits(int ndigits=0)
Properties of an ellipsoid.
Exact geodesic calculations.
Header for GeographicLib::PolygonArea class.
Exception handling for GeographicLib.
Math::real Longitude() const
Header for GeographicLib::DMS class.