osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #ifndef OSGEARTH_UTIL_FORMATTERS_H 00020 #define OSGEARTH_UTIL_FORMATTERS_H 00021 00022 #include <osgEarthUtil/Common> 00023 #include <osgEarth/SpatialReference> 00024 #include <osgEarth/Units> 00025 00026 namespace osgEarth { namespace Util 00027 { 00028 using namespace osgEarth; 00029 00030 class OSGEARTHUTIL_EXPORT LatLongFormatter 00031 { 00032 public: 00033 enum AngularFormat { 00034 FORMAT_DEFAULT, 00035 FORMAT_DECIMAL_DEGREES, 00036 FORMAT_DEGREES_DECIMAL_MINUTES, 00037 FORMAT_DEGREES_MINUTES_SECONDS 00038 }; 00039 00040 enum Options { 00041 USE_SYMBOLS = 1 << 0, // whether to use symbols 00042 USE_COLONS = 1 << 1, // whether to separate components with colons 00043 USE_SPACES = 1 << 2 // whether to separate components with spaces 00044 }; 00045 00046 public: 00047 LatLongFormatter( 00048 const AngularFormat& defaultFormat =FORMAT_DEGREES_MINUTES_SECONDS, 00049 unsigned optionsMask =(USE_SYMBOLS | USE_SPACES) ); 00050 00054 void setPrecision( int value ) { _prec = value; } 00055 00059 void setOptions( const Options& options ) { _options = options; } 00060 00064 std::string format( 00065 const Angular& angle, 00066 int precision =-1, 00067 const AngularFormat& format =FORMAT_DEFAULT); 00068 00072 bool parseAngle( const std::string& input, Angular& out_value ); 00073 00074 protected: 00075 unsigned _options; 00076 AngularFormat _defaultFormat; 00077 int _prec; 00078 }; 00079 00080 //------------------------------------------------------------------------ 00081 00090 class OSGEARTHUTIL_EXPORT MGRSFormatter 00091 { 00092 public: 00093 enum Precision 00094 { 00095 PRECISION_100000M = 100000, // i.e., omit the numerical offsets altogether 00096 PRECISION_10000M = 10000, 00097 PRECISION_1000M = 1000, 00098 PRECISION_100M = 100, 00099 PRECISION_10M = 10, 00100 PRECISION_1M = 1 00101 }; 00102 00103 enum Options 00104 { 00105 USE_SPACES = 1 << 0, // insert spaces between MGRS elements 00106 FORCE_AA_SCHEME = 1 << 1, // use the AA row lettering scheme regardless of ellipsoid 00107 FORCE_AL_SCHEME = 1 << 2 // use the AL row lettering scheme regardless of ellipsoid 00108 }; 00109 00110 public: 00119 MGRSFormatter( 00120 Precision precision =PRECISION_1M, 00121 const SpatialReference* refSRS =0L, 00122 unsigned options =0); 00123 00127 std::string format( double latDeg, double lonDeg ) const; 00128 00129 private: 00130 osg::ref_ptr<const SpatialReference> _refSRS; 00131 bool _useAL; 00132 Precision _precision; 00133 unsigned _options; 00134 }; 00135 00136 } } // namespace osgEarth::Util 00137 00138 #endif // OSGEARTH_UTIL_FORMATTERS_H