37 # pragma warning (disable: 4127)
40 #include "Planimeter.usage"
42 int main(
int argc,
char* argv[]) {
44 using namespace GeographicLib;
47 a = Constants::WGS84_a<real>(),
48 f = Constants::WGS84_f<real>();
49 bool reverse =
false, sign =
true, polyline =
false;
50 std::string istring, ifile, ofile, cdelim;
53 for (
int m = 1; m < argc; ++m) {
54 std::string arg(argv[m]);
61 else if (arg ==
"-e") {
62 if (m + 2 >= argc)
return usage(1,
true);
64 a = Utility::num<real>(std::string(argv[m + 1]));
65 f = Utility::fract<real>(std::string(argv[m + 2]));
67 catch (
const std::exception& e) {
68 std::cerr <<
"Error decoding arguments of -e: " << e.what() <<
"\n";
72 }
else if (arg ==
"--input-string") {
73 if (++m == argc)
return usage(1,
true);
75 }
else if (arg ==
"--input-file") {
76 if (++m == argc)
return usage(1,
true);
78 }
else if (arg ==
"--output-file") {
79 if (++m == argc)
return usage(1,
true);
81 }
else if (arg ==
"--line-separator") {
82 if (++m == argc)
return usage(1,
true);
83 if (std::string(argv[m]).size() != 1) {
84 std::cerr <<
"Line separator must be a single character\n";
88 }
else if (arg ==
"--comment-delimiter") {
89 if (++m == argc)
return usage(1,
true);
91 }
else if (arg ==
"--version") {
93 << argv[0] <<
": GeographicLib version "
94 << GEOGRAPHICLIB_VERSION_STRING <<
"\n";
97 return usage(!(arg ==
"-h" || arg ==
"--help"), arg !=
"--help");
100 if (!ifile.empty() && !istring.empty()) {
101 std::cerr <<
"Cannot specify --input-string and --input-file together\n";
104 if (ifile ==
"-") ifile.clear();
105 std::ifstream infile;
106 std::istringstream instring;
107 if (!ifile.empty()) {
108 infile.open(ifile.c_str());
109 if (!infile.is_open()) {
110 std::cerr <<
"Cannot open " << ifile <<
" for reading\n";
113 }
else if (!istring.empty()) {
114 std::string::size_type m = 0;
116 m = istring.find(lsep, m);
117 if (m == std::string::npos)
121 instring.str(istring);
123 std::istream* input = !ifile.empty() ? &infile :
124 (!istring.empty() ? &instring : &std::cin);
126 std::ofstream outfile;
127 if (ofile ==
"-") ofile.clear();
128 if (!ofile.empty()) {
129 outfile.open(ofile.c_str());
130 if (!outfile.is_open()) {
131 std::cerr <<
"Cannot open " << ofile <<
" for writing\n";
135 std::ostream* output = !ofile.empty() ? &outfile : &std::cout;
142 real perimeter, area;
144 std::string eol(
"\n");
145 while (std::getline(*input, s)) {
146 if (!cdelim.empty()) {
147 std::string::size_type m = s.find(cdelim);
148 if (m != std::string::npos) {
149 eol =
" " + s.substr(m) +
"\n";
153 bool endpoly = s.empty();
165 num = poly.
Compute(reverse, sign, perimeter, area);
167 *output << num <<
" "
176 poly.
AddPoint(p.Latitude(), p.Longitude());
178 num = poly.
Compute(reverse, sign, perimeter, area);
180 *output << num <<
" "
190 catch (
const std::exception& e) {
191 std::cerr <<
"Caught exception: " << e.what() <<
"\n";
195 std::cerr <<
"Caught unknown exception\n";
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
int main(int argc, char *argv[])
Conversion between geographic coordinates.
static const int extradigits
Header for GeographicLib::GeoCoords class.
Header for GeographicLib::PolygonArea class.
Exception handling for GeographicLib.
unsigned Compute(bool reverse, bool sign, real &perimeter, real &area) const
void AddPoint(real lat, real lon)
Header for GeographicLib::DMS class.