#ifndef __JUTM__JUTMGRID__ #define __JUTM__JUTMGRID__ #include #include #include #include #include #include "JLang/JException.hh" #include "JLang/JEquals.hh" #include "JIO/JSerialisable.hh" #include "JIO/JSTDIO.hh" /** * \author mdejong */ namespace JUTM {} namespace JPP { using namespace JUTM; } namespace JUTM { using JLANG::JParseError; using JLANG::JEquals; using JIO::JReader; using JIO::JWriter; /** * Data structure for UTM grid. * This data structure is composed of: * - World Geodetic System; * - UTM zone; */ class JUTMGrid : public JEquals { public: /** * Default constructor. */ JUTMGrid() : key ("?"), wgs ("?"), zone("?") {} /** * Constructor. * * \param key key * \param wgs WGS * \param zone UTM zone */ JUTMGrid(const std::string& key, const std::string& wgs, const std::string& zone) { this->key = key; this->wgs = wgs; this->zone = zone; } /** * Get UTM grid. * * \return UTM grid */ const JUTMGrid& getUTMGrid() const { return static_cast(*this); } /** * Set UTM grid. * * \param grid UTM grid */ void setUTMGrid(const JUTMGrid& grid) { static_cast(*this) = grid; } /** * Get key. * * \return key */ const std::string& getKey() const { return key; } /** * Get WGS. * * \return WGS */ const std::string& getWGS() const { return wgs; } /** * Get UTM zone. * * \return UTM zone */ const std::string& getUTMZone() const { return zone; } /** * Get UTM zone by numerical value. * * \return UTM zone */ int getUTMValue() const { using namespace std; int value = 0; for (string::const_iterator i = zone.begin(); i != zone.end(); ++i) { if (isdigit(*i)) value = 10 * value + (*i - '0'); else break; } return value; } /** * Check equality. * * \param grid UTM grid * \return true if grids are equal; else false */ bool equals(const JUTMGrid& grid) const { return (this->getKey() == grid.getKey() && this->getWGS() == grid.getWGS() && this->getUTMValue() == grid.getUTMValue()); } /** * Convert UTM grid. * * \return UTM grid */ std::string toString() const { return (key + " " + wgs + " " + zone); } /** * Extract UTM grid. * * \param buffer WGS and UTM zone * \return UTM grid */ static JUTMGrid valueOf(const std::string& buffer) { JUTMGrid grid; std::istringstream is(buffer); if (is >> grid) return grid; else throw JParseError("JUTMGrid::valueOf()"); } /** * Read UTM grid from input. * * \param in input stream * \param grid UTM grid * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JUTMGrid& grid) { return in >> grid.key >> grid.wgs >> grid.zone; } /** * Write UTM grid to output. * * \param out output stream * \param grid UTM grid * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JUTMGrid& grid) { return out << grid.key << ' ' << grid.wgs << ' ' << grid.zone; } /** * Read UTM grid from input. * * \param in input stream * \param grid UTM grid * \return input stream */ friend inline JReader& operator>>(JReader& in, JUTMGrid& grid) { using namespace JIO; return in >> grid.key >> grid.wgs >> grid.zone; } /** * Write UTM grid to output. * * \param out output stream * \param grid UTM grid * \return output stream */ friend inline JWriter& operator<<(JWriter& out, const JUTMGrid& grid) { using namespace JIO; return out << grid.key << grid.wgs << grid.zone; } protected: std::string key; std::string wgs; std::string zone; }; } #endif