GeoPoint.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef GEOPOINT_H
00011 #define GEOPOINT_H
00012 
00013 #include "LocationType.h"
00014 #include "EnumWrapper.h"
00015 #include "TypesFile.h"
00016 
00017 #include <string>
00018 
00019 /**
00020  *  Adds text formatting for a latitude or longitude value.
00021  *
00022  *  This class provides common formatting to a single latutude or longitude value.
00023  *  When the data value is set, it can be retrieved either in the raw data value
00024  *  format, or in one of several text formats, as defined by the DmsType enum.
00025  *
00026  *  @see        LatLonPoint
00027  */
00028 class DmsPoint
00029 {
00030 public:
00031    /**
00032     *  Specifies the text formatting type for the data value.
00033     *
00034     *  @see     DmsPoint::getValueText()
00035     */
00036    enum DmsTypeEnum
00037    {
00038       DMS_DECIMAL,      /**< The value is interpreted as neither latitude or longitude,
00039                              and a negative sign or the absence of one indicates the
00040                              hemisphere in the text. */
00041       DMS_LATITUDE,     /**< The value is interpreted as latitude, and the hemisphere
00042                              is designated by 'N' or 'S' in the text. */
00043       DMS_LONGITUDE     /**< The value is interpreted as longitude, and the hemisphere
00044                              is designated by 'E' or 'W' in the text. */
00045    };
00046 
00047    /**
00048     * @EnumWrapper DmsPoint::DmsTypeEnum.
00049     */
00050    typedef EnumWrapper<DmsTypeEnum> DmsType;
00051 
00052    /**
00053     *  Creates a DMS point with an initial raw value.
00054     *
00055     *  @param   eType
00056     *           The DMS point type.
00057     *  @param   dValue
00058     *           The initial value for the DMS point.
00059     *
00060     *  @see     DmsType
00061     */
00062    DmsPoint(DmsType eType, double dValue = 0.0);
00063 
00064    /**
00065     *  Creates a DMS point with an initial string value.
00066     *
00067     *  @param   eType
00068     *           The DMS point type.
00069     *  @param   valueText
00070     *           A string representing the initial value that can be converted to a
00071     *           numeric raw value.
00072     */
00073    DmsPoint(DmsType eType, const std::string& valueText);
00074 
00075    /**
00076     *  Destroys the DMS point.
00077     */
00078    ~DmsPoint();
00079 
00080    /**
00081     *  Returns the DMS point type.
00082     *
00083     *  @return  The DMS type of the DMS point.
00084     *
00085     *  @see     DmsType
00086     */
00087    DmsType getType() const;
00088 
00089    /**
00090     *  Sets the value as a raw value.
00091     *
00092     *  @param   dValue
00093     *           The new value for the DMS point.
00094     */
00095    void setValue(double dValue);
00096 
00097    /**
00098     *  Sets the value as a string.
00099     *
00100     *  @param   valueText
00101     *           A string representing the new value that can be converted to a numeric
00102     *           raw value.
00103     */
00104    void setValue(const std::string& valueText);
00105 
00106    /**
00107     *  Returns the raw value of the DMS point.
00108     *
00109     *  @return  The DMS point raw value.
00110     *
00111     *  @see     getValueText()
00112     */
00113    double getValue() const;
00114 
00115    /**
00116     *  Returns the value of the DMS point in a given text format.
00117     *
00118     *  @param   format
00119     *           The text format for the string.
00120     *  @param   precision
00121     *           The number of digits after decimal point. Defaults to three for
00122     *           decimal degrees and seconds and two for decimal minutes.
00123     *
00124     *  @return  The value of the DMS point as an formatted string.
00125     *
00126     *  @see     DmsFormatType, getValue()
00127     */
00128    std::string getValueText(DmsFormatType format = DMS_FULL, int precision = -1) const;
00129 
00130    /**
00131     *  Sets the type and value to that of another DMS point.
00132     *
00133     *  @param   original
00134     *           The point from which to set this point's type and value.
00135     *
00136     *  @return  A reference to this DMS point, whose type and value have changed.
00137     */
00138    DmsPoint& operator =(const DmsPoint& original);
00139 
00140    /**
00141     *  Compares two DMS points.
00142     *
00143     *  @param   rhs
00144     *           The point to compare the type and value against this point.
00145     *
00146     *  @return  Returns true if the type and value of the given point are identical
00147     *           to the type and value of this point; otherwise returns false.
00148     */
00149    bool operator ==(const DmsPoint& rhs) const;
00150 
00151 private:
00152    DmsType mType;
00153    double mValue;
00154 };
00155 
00156 /**
00157  *  Stores a latitude/longitude coordinate pair.
00158  *
00159  *  This class stores a latitude/longitude pair as DmsPoint objects to provide
00160  *  common text formatting when retrieving the value.  In addition to the text
00161  *  formatting, the raw value can also be retrieved.
00162  *
00163  *  @see        DmsPoint
00164  */
00165 class LatLonPoint
00166 {
00167 public:
00168    /**
00169     *  Creates a latitude/longitude point with an initial value of 0° N and 0° E.
00170     */
00171    LatLonPoint();
00172 
00173    /**
00174     *  Creates a latitude/longitude point with initial raw values.
00175     *
00176     *  @param   latLon
00177     *           The initial latitude and longitude coordinate.  The latitude value
00178     *           must correspond to the x-coordinate of the LocationType, and the
00179     *           longitude value must correspond to the y-coordinate.
00180     */
00181    LatLonPoint(LocationType latLon);
00182 
00183    /**
00184     *  Creates a latitude/longitude point with a initial string values for both
00185     *  latitude and longitude.
00186     *
00187     *  @param   latitudeText
00188     *           A string representing the initial latitude value that can be
00189     *           converted to a numeric raw value.
00190     *  @param   longitudeText
00191     *           A string representing the initial longitude value that can be
00192     *           converted to a numeric raw value.
00193     */
00194    LatLonPoint(const std::string& latitudeText, const std::string& longitudeText);
00195 
00196    /**
00197     *  Creates a latitude/longitude point with an initial string value.
00198     *
00199     *  @param   latLonText
00200     *           A string representing the initial latitude and longitude value that
00201     *           can be converted to numeric raw values.
00202     */
00203    LatLonPoint(const std::string& latLonText);
00204 
00205    /**
00206     *  Destroys the latitude/longitude point.
00207     */
00208    ~LatLonPoint();
00209 
00210    /**
00211     *  Returns the raw value of the latitude/longitude point.
00212     *
00213     *  @return  The latitude/longitude coordinate.  The latitude value is stored in
00214     *           the LocationType x-coordinate, and the longitude value is stored in
00215     *           the y-coordinate.
00216     *
00217     *  @see     getLatitude(), getLongitude(), getText()
00218     */
00219    LocationType getCoordinates() const;
00220 
00221    /**
00222     *  Retrieves the latitude value.
00223     *
00224     *  @return  A reference to the DMS point containing the latitude value.
00225     *
00226     *  @see     DmsPoint
00227     */
00228    const DmsPoint& getLatitude() const;
00229 
00230    /**
00231     *  Retrieves the longitude value.
00232     *
00233     *  @return  A reference to the DMS point containing the longitude value.
00234     *
00235     *  @see     DmsPoint
00236     */
00237    const DmsPoint& getLongitude() const;
00238 
00239    /**
00240     *  Returns the latitude/longitude coordinate in a given text format.
00241     *
00242     *  @param   format
00243     *           The text format for the string.
00244     *  @param   precision
00245     *           The number of digits after decimal point. Defaults to three for
00246     *           decimal degrees and seconds and two for decimal minutes.
00247     *
00248     *  @return  The value of the latitude/longitude coordinate as a formatted string.
00249     *
00250     *  @see     DmsFormatType, getCoordinates(), getLatitudeText(), getLongitudeText()
00251     */
00252    std::string getText(DmsFormatType format = DMS_FULL, int precision = -1) const;
00253 
00254    /**
00255     *  Returns the latitude value in a given text format.
00256     *
00257     *  @param   format
00258     *           The text format for the string.
00259     *  @param   precision
00260     *           The number of digits after decimal point. Defaults to three for
00261     *           decimal degrees and seconds and two for decimal minutes.
00262     *
00263     *  @return  The latitude value as a formatted string.
00264     *
00265     *  @see     DmsFormatType, getText(), getLongitudeText()
00266     */
00267    std::string getLatitudeText(DmsFormatType format = DMS_FULL, int precision = -1) const;
00268 
00269    /**
00270     *  Returns the longitude value in a given text format.
00271     *
00272     *  @param   format
00273     *           The text format for the string.
00274     *  @param   precision
00275     *           The number of digits after decimal point. Defaults to three for
00276     *           decimal degrees and seconds and two for decimal minutes.
00277     *
00278     *  @return  The longitude value as a formatted string.
00279     *
00280     *  @see     DmsFormatType, getText(), getLatitudeText()
00281     */
00282    std::string getLongitudeText(DmsFormatType format = DMS_FULL, int precision = -1) const;
00283 
00284    /**
00285     *  Sets the latitude and longitude values to that of another latitude/longitude
00286     *  point.
00287     *
00288     *  @param   original
00289     *           The point from which to set this point's values.
00290     *
00291     *  @return  A reference to this latitude/longitude point, whose values have
00292     *           changed.
00293     */
00294    LatLonPoint& operator =(const LatLonPoint& original);
00295 
00296    /**
00297     *  Compares two latitude/longitude points.
00298     *
00299     *  @param   rhs
00300     *           The latitude/longitude point to compare the values against this
00301     *           point.
00302     *
00303     *  @return  Returns true if the values of the given point are identical to the
00304     *           values of this point; otherwise returns false.
00305     */
00306    bool operator ==(const LatLonPoint& rhs) const;
00307 
00308 private:
00309    DmsPoint mLatitude;
00310    DmsPoint mLongitude;
00311 };
00312 
00313 /**
00314  *  Stores a Universal Transverse Mercator (UTM) coordinate.
00315  *
00316  *  This class stores a UTM coordinate and provides common text formatting when
00317  *  retrieving the value.  In addition to the text formatting, the raw easting,
00318  *  northing, zone, and hemisphere values can also be retrieved.
00319  */
00320 class UtmPoint
00321 {
00322 public:
00323    /**
00324     *  Creates a UTM point based on a given latitude/longitude point.
00325     *
00326     *  This constructor automatically converts a latitude/longitude coordinate
00327     *  pair into a UTM coordinate.
00328     * 
00329     *  @param   latLon
00330     *           The latitude/longitude coordinate to convert to a UTM point.
00331     */
00332    UtmPoint(LatLonPoint latLon);
00333 
00334    /**
00335     *  Creates a UTM point based on initial easting, northing, zone, and
00336     *  hemisphere values.
00337     *
00338     *  @param   dEasting
00339     *           The easting value.
00340     *  @param   dNorthing
00341     *           The northing value.
00342     *  @param   iZone
00343     *           The integer zone value.
00344     *  @param   hemisphere
00345     *           The hemisphere, as a character, which should be either 'N'
00346     *           or 'S'.
00347     */
00348    UtmPoint(double dEasting, double dNorthing, int iZone, char hemisphere);
00349 
00350    /**
00351     *  Destroys the UTM point.
00352     */
00353    ~UtmPoint();
00354 
00355    /**
00356     *  Retrieves the easting and northing values.
00357     *
00358     *  @return  The easting and northing values in a LocationType.  The easting
00359     *           value is stored in the LocationType x-coordinate, and the
00360     *           northing value is stored in the y-coordinate.
00361     *
00362     *  @see     getEasting(), getNorthing(), getText()
00363     */
00364    LocationType getCoordinates() const;
00365 
00366    /**
00367     *  Converts the UTM point to a latitude/longitude point.
00368     *
00369     *  @return  The UTM point converted to a latitude/longitude coordinate.  The
00370     *           latitude value is stored in the LocationType x-coordinate, and
00371     *           the longitude value is stored in the y-coordinate.
00372     *
00373     *  @see     LatLonPoint, getCoordinates()
00374     */
00375    LatLonPoint getLatLonCoordinates() const;
00376 
00377    /**
00378     *  Returns the easting value.
00379     *
00380     *  @return  The easting value of the UTM point.
00381     *
00382     *  @see     getNorthing()
00383     */
00384    double getEasting() const;
00385 
00386    /**
00387     *  Returns the northing value.
00388     *
00389     *  @return  The northing value of the UTM point.
00390     *
00391     *  @see     getEasting()
00392     */
00393    double getNorthing() const;
00394 
00395    /**
00396     *  Returns the zone value.
00397     *
00398     *  @return  The zone value of the UTM point as an integer.
00399     */
00400    int getZone() const;
00401 
00402    /**
00403     *  Returns the hemisphere value.
00404     *
00405     *  @return  The hemisphere value of the UTM point as a character.  Will be
00406     *           either 'N' or 'S'.
00407     */
00408    const char getHemisphere() const;
00409 
00410    /**
00411     *  Returns UTM point in a formatted string.
00412     *
00413     *  @return  A string representing the UTM point in the following format:
00414     *           easting text + " " + zone text + ", " + northing text + " " +
00415     *           hemisphere.
00416     *
00417     *  @see     getEastingText(), getNorthingText(), getZoneText(), getHemisphere()
00418     */
00419    std::string getText() const;
00420 
00421    /**
00422     *  Returns the easting value as a formatted string.
00423     *
00424     *  @return  A string representing the easting value of the UTM point in the
00425     *           following format used by sprintf(): "E%.0f".
00426     *
00427     *  @see     getText()
00428     */
00429    std::string getEastingText() const;
00430 
00431    /**
00432     *  Returns the northing value as a formatted string.
00433     *
00434     *  @return  A string representing the northing value of the UTM point in the
00435     *           following format used by sprintf(): "N%.0f".
00436     *
00437     *  @see     getText()
00438     */
00439    std::string getNorthingText() const;
00440 
00441    /**
00442     *  Returns the zone value as a formatted string.
00443     *
00444     *  @return  A string representing the zone value of the UTM point in the
00445     *           following format used by sprintf(): "Zone %d".
00446     *
00447     *  @see     getText()
00448     */
00449    std::string getZoneText() const;
00450 
00451 private:
00452    double mEasting;
00453    double mNorthing;
00454    int mZone;
00455    char mHemisphere;
00456 };
00457 
00458 /**
00459  *  Stores a Military Grid Reference System (MGRS) coordinate.
00460  *
00461  *  This class stores an MGRS coordinate and provides common text formatting when
00462  *  retrieving the value.  In addition to the text formatting, the raw component
00463  *  values can also be retrieved.
00464  */
00465 class MgrsPoint
00466 {
00467 public:
00468    /**
00469     *  Creates an MGRS point based on a given latitude/longitude point.
00470     *
00471     *  This constructor automatically converts a latitude/longitude coordinate
00472     *  pair into an MGRS coordinate.
00473     * 
00474     *  @param   latLon
00475     *           The latitude/longitude coordinate to convert to an MGRS point.
00476     */
00477    MgrsPoint(LatLonPoint latLon);
00478 
00479    /**
00480     *  Creates an MGRS point based on its string representation.
00481     *
00482     *  @param   mgrsText
00483     *           A string representation of the MGRS point.
00484     */
00485    MgrsPoint(const std::string& mgrsText);
00486 
00487    /**
00488     *  Destroys the MGRS point.
00489     */
00490    ~MgrsPoint();
00491 
00492    /**
00493     *  Retrieves the easting and northing components of the MGRS point.
00494     *
00495     *  @return  The easting and northing component values in a LocationType.  The
00496     *           easting value is stored in the LocationType x-coordinate, and the
00497     *           northing value is stored in the y-coordinate.
00498     *
00499     *  @see     getEasting(), getNorthing(), getText()
00500     */
00501    LocationType getCoordinates() const;
00502 
00503    /**
00504     *  Converts the MGRS point to a latitude/longitude point.
00505     *
00506     *  @return  The MGRS point converted to a latitude/longitude coordinate.  The
00507     *           latitude value is stored in the LocationType x-coordinate, and
00508     *           the longitude value is stored in the y-coordinate.
00509     *
00510     *  @see     LatLonPoint, getCoordinates()
00511     */
00512    LatLonPoint getLatLonCoordinates() const;
00513 
00514    /**
00515     *  Returns the easting component value.
00516     *
00517     *  @return  The easting value of the MGRS point.
00518     *
00519     *  @see     getNorthing()
00520     */
00521    double getEasting() const;
00522 
00523    /**
00524     *  Returns the northing component value.
00525     *
00526     *  @return  The northing value of the MGRS point.
00527     *
00528     *  @see     getEasting()
00529     */
00530    double getNorthing() const;
00531 
00532    /**
00533     *  Returns the zone component value.
00534     *
00535     *  @return  The zone value of the MGRS point as an integer.
00536     */
00537    int getZone() const;
00538 
00539    /**
00540     *  Returns the text representation of the MGRS point.
00541     *
00542     *  @return  A formatted string representing the MGRS point, including the
00543     *           easting, northing, zone, and SCR code.
00544     */
00545    std::string getText() const;
00546 
00547    /**
00548     *  Returns the zone component value as a formatted string.
00549     *
00550     *  @return  A string representing the zone value of the MGRS point in the
00551     *           format used in the string representation of the entire coordinate.
00552     *
00553     *  @see     getText()
00554     */
00555    std::string getZoneText() const;
00556 
00557    /**
00558     *  Returns the MGRS code representing a region in which the point resides.
00559     *
00560     *  @return  The alphabetic character string representing a 100 km MGRS region
00561     *           in which the MGRS point resides.
00562     *
00563     *  @see     getText()
00564     */
00565    std::string getScrCodeText() const;
00566 
00567 private:
00568    std::string mText;
00569 };
00570 
00571 #endif

Software Development Kit - Opticks 4.9.0 Build 16218