#ifndef __JUTM__JUTMPOSITION__ #define __JUTM__JUTMPOSITION__ #include #include #include "JGeometry3D/JPosition3D.hh" #include "JMath/JMath.hh" #include "JLang/JManip.hh" #include "JIO/JSerialisable.hh" /** * \author mdejong */ namespace JUTM {} namespace JPP { using namespace JUTM; } /** * Auxiliaries for handling universal transverse mercator coordinate system (UTM). */ namespace JUTM { using JMATH::JMath; using JGEOMETRY3D::JVector3D; using JGEOMETRY3D::JPosition3D; using JIO::JReader; using JIO::JWriter; /** * Data structure for UTM position. * The z-coordinate corresponds to the depth where z = 0 is at sea level. */ class JUTMPosition : public JMath { public: /** * Default constructor. */ JUTMPosition() : east (0.0), north(0.0), z (0.0) {} /** * Constructor. * * \param pos UTM position */ JUTMPosition(const JVector3D& pos) : east (pos.getX()), north(pos.getY()), z (pos.getZ()) {} /** * Constructor. * * \param east UTM East * \param north UTM North * \param z UTM Z */ JUTMPosition(const double east, const double north, const double z) { this->east = east; this->north = north; this->z = z; } /** * Get UTM position. * * \return position */ const JUTMPosition& getUTMPosition() const { return static_cast(*this); } /** * Set UTM position. * * \param position position */ void setUTMPosition(const JUTMPosition& position) { static_cast(*this) = position; } /** * Get position. * * \return position */ JPosition3D getPosition() const { return JPosition3D(this->getX(), this->getY(), this->getZ()); } /** * Type conversion operator. * * \return position */ operator JPosition3D() const { return getPosition(); } /** * Get UTM east. * * \return UTM East */ double getUTMEast() const { return this->east; } /** * Get UTM north. * * \return UTM North */ double getUTMNorth() const { return this->north; } /** * Get UTM Z. * * \return UTM Z */ double getUTMZ() const { return this->z; } /** * Get x. * * \return UTM East */ double getX() const { return this->east; } /** * Get y. * * \return UTM North */ double getY() const { return this->north; } /** * Get z. * * \return UTM Z */ double getZ() const { return this->z; } /** * Negate UTM position. * * \return this UTM position */ JUTMPosition& negate() { east = -east; north = -north; z = -z; return *this; } /** * Add UTM position. * * \param pos UTM position * \return this UTM position */ JUTMPosition& add(const JUTMPosition& pos) { east += pos.getUTMEast(); north += pos.getUTMNorth(); z += pos.getUTMZ(); return *this; } /** * Subtract UTM position. * * \param pos UTM position * \return this UTM position */ JUTMPosition& sub(const JUTMPosition& pos) { east -= pos.getUTMEast(); north -= pos.getUTMNorth(); z -= pos.getUTMZ(); return *this; } /** * Scale UTM position. * * \param factor multiplication factor * \return this UTM position */ JUTMPosition& mul(const double factor) { east *= factor; north *= factor; z *= factor; return *this; } /** * Scale UTM position. * * \param factor division factor * \return this UTM position */ JUTMPosition& div(const double factor) { east /= factor; north /= factor; z /= factor; return *this; } /** * Get displacement to position. * * The displacement corresponds to the 2D distance in the (East,North) plane. * * \param position position * \return displacement */ double getDisplacement(const JUTMPosition& position) const { const double x = this->getUTMEast() - position.getUTMEast(); const double y = this->getUTMNorth() - position.getUTMNorth(); return sqrt(x*x + y*y); } /** * Read UTM position from input. * * \param in input stream * \param pos UTM position * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos) { return in >> pos.east >> pos.north >> pos.z; } /** * Write UTM position to output. * * \param out output stream * \param pos UTM position * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos) { const JFormat format[] = { JFormat(out, getFormat(JFormat_t(12, 3, std::ios::fixed | std::ios::showpos))), JFormat(out, getFormat (JFormat_t( 9, 3, std::ios::fixed | std::ios::showpos))) }; return out << format[0] << pos.east << ' ' << format[0] << pos.north << ' ' << format[1] << pos.z; } /** * Read UTM position from input. * * \param in input stream * \param pos UTM position * \return input stream */ friend inline JReader& operator>>(JReader& in, JUTMPosition& pos) { return in >> pos.east >> pos.north >> pos.z; } /** * Write UTM position to output. * * \param out output stream * \param pos UTM position * \return output stream */ friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos) { return out << pos.east << pos.north << pos.z; } protected: double east; double north; double z; }; static const JUTMPosition JNorth_t(0,+1,0); //!< North static const JUTMPosition JEast_t (+1,0,0); //!< East static const JUTMPosition JSouth_t(0,-1,0); //!< South static const JUTMPosition JWest_t (-1,0,0); //!< West } #endif