Advertisement
Guest User

GeoDataCoordinates.h

a guest
May 15th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.62 KB | None | 0 0
  1. //
  2. // This file is part of the Marble Virtual Globe.
  3. //
  4. // This program is free software licensed under the GNU LGPL. You can
  5. // find a copy of this license in LICENSE.txt in the top directory of
  6. // the source code.
  7. //
  8. // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
  9. // Copyright 2007-2008 Inge Wallin  <ingwa@kde.org>
  10. // Copyright 2008      Patrick Spendrin <ps_ml@gmx.de>
  11. //
  12.  
  13.  
  14. #ifndef MARBLE_GEODATACOORDINATES_H
  15. #define MARBLE_GEODATACOORDINATES_H
  16.  
  17. #include <QtCore/QCoreApplication>
  18. #include <QtCore/QMetaType>
  19. #include <QtCore/QVector>
  20. #include <QtCore/QString>
  21.  
  22. #include <cmath>
  23.  
  24. /* M_PI is a #define that may or may not be handled in <cmath> */
  25. #ifndef M_PI
  26. #define M_PI 3.14159265358979323846264338327950288419717
  27. #endif
  28.  
  29. #include "geodata_export.h"
  30. #include "global.h"
  31.  
  32. namespace Marble
  33. {
  34.  
  35. const qreal TWOPI = 2 * M_PI;
  36.  
  37. class GeoDataCoordinatesPrivate;
  38. class Quaternion;
  39. class MarbleClock;
  40.  
  41. /**
  42.  * @short A 3d point representation
  43.  *
  44.  * GeoDataCoordinates is the simple representation of a single three
  45.  * dimensional point. It can be used all through out marble as the data type
  46.  * for three dimensional objects. it comprises of a Quaternion for speed issues.
  47.  * This class was introduced to reflect the difference between a simple 3d point
  48.  * and the GeoDataGeometry object containing such a point. The latter is a
  49.  * GeoDataPoint and is simply derived from GeoDataCoordinates.
  50.  * @see GeoDataPoint
  51. */
  52.  
  53. class GEODATA_EXPORT GeoDataCoordinates
  54. {
  55.  Q_DECLARE_TR_FUNCTIONS(GeoDataCoordinates)
  56.  
  57.  public:
  58.     /**
  59.      * @brief enum used constructor to specify the units used
  60.      *
  61.      * Internally we always use radian for mathematical convenience.
  62.      * However the Marble's interfaces to the outside should default
  63.      * to degrees.
  64.      */
  65.     enum Unit{
  66.         Radian,
  67.         Degree
  68.     };
  69.  
  70.     /**
  71.      * @brief enum used to specify the notation / numerical system
  72.      *
  73.      * For degrees there exist two notations:
  74.      * "Decimal" (base-10) and the "Sexagesimal DMS" (base-60) which is
  75.      * traditionally used in cartography. Decimal notation
  76.      * uses floating point numbers to specify parts of a degree. The
  77.      * Sexagesimal DMS notation uses integer based
  78.      * Degrees-(Arc)Minutes-(Arc)Seconds to describe parts of a degree.
  79.      */
  80.     enum Notation{
  81.         Decimal,
  82.         DMS
  83.     };
  84.  
  85.     // Type definitions
  86.     typedef QVector<GeoDataCoordinates> Vector;
  87.     typedef QVector<GeoDataCoordinates*> PtrVector;
  88.  
  89.     GeoDataCoordinates( const GeoDataCoordinates& other );
  90.     GeoDataCoordinates();
  91.  
  92.     /**
  93.      * @brief create a geocoordinate from longitude and latitude
  94.      * @param _lon longitude
  95.      * @param _lat latitude
  96.      * @param alt altitude in meters (default: 0)
  97.      * @param _unit units that lon and lat get measured in
  98.      * (default for Radian: north pole at pi/2, southpole at -pi/2)
  99.      * @param _detail detail (default: 0)
  100.      */
  101.     GeoDataCoordinates( qreal lon, qreal lat, qreal alt = 0,
  102.                         GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian,
  103.                         int detail = 0 );
  104.  
  105.     virtual ~GeoDataCoordinates();
  106.  
  107.     /**
  108.     * @brief (re)set the coordinates in a GeoDataCoordinates object
  109.     * @param _lon longitude
  110.     * @param _lat latitude
  111.     * @param alt altitude in meters (default: 0)
  112.     * @param _unit units that lon and lat get measured in
  113.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  114.     */
  115.     void set( qreal lon, qreal lat, qreal alt = 0,
  116.               GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian );
  117.  
  118.     /**
  119.     * @brief use this function to get the longitude and latitude with one
  120.     * call - use the unit parameter to switch between Radian and DMS
  121.     * @param lon longitude
  122.     * @param lat latitude
  123.     * @param unit units that lon and lat get measured in
  124.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  125.     */
  126.     void geoCoordinates( qreal& lon, qreal& lat,
  127.                          GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian )
  128.                                                                 const;
  129.  
  130.     /**
  131.     * @brief use this function to get the longitude, latitude and altitude
  132.     * with one call - use the unit parameter to switch between Radian and DMS
  133.     * @param lon longitude
  134.     * @param lat latitude
  135.     * @param alt altitude in meters
  136.     * @param unit units that lon and lat get measured in
  137.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  138.     */
  139.     void geoCoordinates( qreal& lon, qreal& lat, qreal& alt,
  140.                          GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian )
  141.                                                                 const;
  142.  
  143.     /**
  144.     * @brief set the longitude in a GeoDataCoordinates object
  145.     * @param _lon longitude
  146.     * @param _unit units that lon and lat get measured in
  147.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  148.     */
  149.     void setLongitude( qreal lon,
  150.               GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian );
  151.  
  152.     /**
  153.     * @brief retrieves the longitude of the GeoDataCoordinates object
  154.     * use the unit parameter to switch between Radian and DMS
  155.     * @param unit units that lon and lat get measured in
  156.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  157.     * @return longitude
  158.     */
  159.     qreal longitude( GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian )
  160.                                                                 const;
  161.  
  162.     /**
  163.     * @brief retrieves the latitude of the GeoDataCoordinates object
  164.     * use the unit parameter to switch between Radian and DMS
  165.     * @param unit units that lon and lat get measured in
  166.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  167.     * @return latitude
  168.     */
  169.     qreal latitude( GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian )
  170.                                                                 const;
  171.  
  172.     /**
  173.     * @brief set the longitude in a GeoDataCoordinates object
  174.     * @param _lat longitude
  175.     * @param _unit units that lon and lat get measured in
  176.     * (default for Radian: north pole at pi/2, southpole at -pi/2)
  177.     */
  178.     void setLatitude( qreal lat,
  179.               GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian );
  180.  
  181.     /**
  182.         * @brief return the altitude of the Point in meters
  183.         */
  184.     qreal altitude() const;
  185.     /**
  186.     * @brief set the altitude of the Point in meters
  187.     * @param altitude altitude
  188.     */
  189.     void setAltitude( const qreal altitude );
  190.  
  191.     /**
  192.     * @brief return the detail flag
  193.     */
  194.     int detail() const;
  195.  
  196.     /**
  197.     * @brief set the detail flag
  198.     * @param det detail
  199.     */
  200.     void setDetail( const int det );
  201.  
  202.     /**
  203.     * @brief return a Quaternion with the used coordinates
  204.     */
  205.     const Quaternion &quaternion() const;
  206.  
  207.     /**
  208.     * @brief return whether our coordinates represent a pole
  209.     * This method can be used to check whether the coordinate equals one of
  210.     * the poles.
  211.     */
  212.     bool isPole( Pole = AnyPole ) const;
  213.  
  214.     /**
  215.     * @brief return Notation of string representation
  216.     */
  217.     static GeoDataCoordinates::Notation defaultNotation();
  218.  
  219.     /**
  220.     * @brief set the Notation of the string representation
  221.     * @param notation Notation
  222.     */
  223.     static void setDefaultNotation( GeoDataCoordinates::Notation notation );
  224.  
  225.     /**
  226.      * @brief normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
  227.      * @param lon longitude
  228.      */
  229.     static qreal normalizeLon( qreal lon,
  230.                                GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
  231.  
  232.     /**
  233.      * @brief normalize latitude to always be in -M_PI / 2. <= lat <= +M_PI / 2 (Radian).
  234.      * @param lat latitude
  235.      */
  236.     static qreal normalizeLat( qreal lat,
  237.                                GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
  238.  
  239.     /**
  240.      * @brief normalize both longitude and latitude at the same time
  241.      * This method normalizes both latitude and longitude, so that the
  242.      * latitude and the longitude stay within the "usual" range.
  243.      * NOTE: If the latitude exceeds M_PI/2 (+90.0 deg) or -M_PI/2 (-90.0 deg)
  244.      * then this will be interpreted as a pole traversion where the point will  
  245.      * end up on the opposite side of the globe. Therefore the longitude will
  246.      * change by M_PI (180 deg).
  247.      * If you don't want this behaviour use both normalizeLat() and
  248.      * normalizeLon() instead.  
  249.      * @param lon the longitude value
  250.      * @param lat the latitude value
  251.      */
  252.     static void normalizeLonLat( qreal &lon, qreal &lat,
  253.                                  GeoDataCoordinates::Unit = GeoDataCoordinates::Radian );
  254.    
  255.     /**
  256.      * @brief try to parse the string into a coordinate pair
  257.      * @param successful becomes true if the conversion succeeds
  258.      * @return the geodatacoordinates
  259.      */    
  260.     static GeoDataCoordinates fromString( const QString &string, bool& successful );
  261.      
  262.     /**
  263.     * @brief return a string representation of the coordinate
  264.     * this is a convenience function which uses the default notation
  265.     */
  266.     QString toString() const;
  267.  
  268.     /**
  269.     * @brief return a string with the notation given by notation
  270.     *
  271.     * @param notation set a notation different from the default one
  272.     * @param precision set the number of digits below degrees.
  273.     * The precision depends on the current notation:
  274.     * For Decimal representation the precision is the number of
  275.     * digits after the decimal point.
  276.     * In DMS a precision of 1 or 2 shows the arc minutes; a precision
  277.     * of 3 or 4 will show arc seconds. A precision beyond that will
  278.     * increase the number of digits after the arc second decimal point.
  279.     */
  280.     QString toString( GeoDataCoordinates::Notation notation, int precision = -1 ) const;
  281.    
  282.     static QString lonToString( qreal lon, GeoDataCoordinates::Notation notation,  
  283.                                            GeoDataCoordinates::Unit unit = Radian,
  284.                                            int precision = -1,
  285.                                            char format = 'f' );
  286.     /**
  287.      * @brief return a string representation of longitude of the coordinate
  288.      * convenience function that uses the default notation
  289.      */
  290.     QString lonToString() const;
  291.  
  292.     static QString latToString( qreal lat, GeoDataCoordinates::Notation notation,
  293.                                            GeoDataCoordinates::Unit unit = Radian,
  294.                                            int precision = -1,
  295.                                            char format = 'f' );
  296.     /**
  297.      * @brief return a string representation of latitude of the coordinate
  298.      * convenience function that uses the default notation
  299.      */
  300.     QString latToString() const;
  301.    
  302.     virtual bool operator==( const GeoDataCoordinates& ) const;
  303.     virtual bool operator !=( const GeoDataCoordinates& ) const;
  304.     GeoDataCoordinates& operator=( const GeoDataCoordinates &other );
  305.  
  306.     /** Serialize the contents of the feature to @p stream. */
  307.     virtual void pack( QDataStream& stream ) const;
  308.     /** Unserialize the contents of the feature from @p stream. */
  309.     virtual void unpack( QDataStream& stream );
  310.  
  311.     virtual void detach();
  312.    
  313.     void setType( int type );
  314.    
  315.     int getType() const;
  316.  
  317.     void setClock( MarbleClock* clock );
  318.    
  319.     MarbleClock* getClock() const;
  320.    
  321.  protected:
  322.     GeoDataCoordinatesPrivate* d;
  323.  
  324.  private:
  325.     static GeoDataCoordinates::Notation s_notation;
  326. };
  327.  
  328. }
  329.  
  330. Q_DECLARE_METATYPE( Marble::GeoDataCoordinates )
  331.  
  332. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement