TerraLib 4.1
E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeProjection.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 TerraLib - a library for developing GIS applications.
00003 Copyright  2001-2007 INPE and Tecgraf/PUC-Rio.
00004 
00005 This code is part of the TerraLib library.
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 You should have received a copy of the GNU Lesser General Public
00012 License along with this library.
00013 
00014 The authors reassure the license terms regarding the warranties.
00015 They specifically disclaim any warranties, including, but not limited to,
00016 the implied warranties of merchantability and fitness for a particular purpose.
00017 The library provided hereunder is on an "as is" basis, and the authors have no
00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
00020 indirect, special, incidental, or consequential damages arising out of the use
00021 of this library and its documentation.
00022 *************************************************************************************/
00027 #ifndef  __TERRALIB_INTERNAL_PROJECTION_H
00028 #define  __TERRALIB_INTERNAL_PROJECTION_H
00029 
00030 #include "TeCoord2D.h"
00031 #include "TeDefines.h"
00032 #include "TeDatum.h"
00033 
00034 #include <stdio.h>
00035 #include <map>
00036 #include <string>
00037 
00038 using namespace std;
00039 
00041 enum TeHemisphere
00042 { TeNORTH_HEM, TeSOUTH_HEM };
00043 
00045 const int NUM_PROJ = 13;
00046 
00048 struct TL_DLL TeProjInfo 
00049 {
00050            int hasUnits;
00051            int hasLon0;
00052            int hasLat0;
00053            int hasStlat1;
00054            int hasStlat2;
00055            int hasScale;
00056            int hasOffx;
00057            int hasOffy;
00058 };
00059 
00061 typedef map<string,TeProjInfo> TeProjInfoMap;
00062 
00064 TL_DLL TeProjInfo TeProjectionInfo ( const string& projName  );
00065 
00066 TL_DLL const char** TeGetProjInfo();
00067 
00068 // ============ PROJECTION PARAMETERS ===============
00069 
00070 class TeProjection;
00071 
00072 //FAMI Added Satellite parameters
00074 struct TL_DLL TeProjectionParams
00075 {
00076            string     name;           
00077            TeDatum datum;       
00078         double        lon0;           
00079            double  lat0;              
00080            double     offx;           
00081            double     offy;           
00082            double     stlat1;         
00083            double  stlat2;      
00084            string  units;       
00085            double  scale;       
00086            TeHemisphere hemisphere; 
00087            double  pri;         
00088            double  prj;         
00089            double  pis;         
00090            double  pjs;         
00091            double  prs;         
00092            double  pscn;        
00093            double  pyaw;        
00094 
00095   TeProjectionParams()
00096   {
00097              name="";      
00098     lon0=0.;               
00099              lat0=0.;        
00100              offx=0.;      
00101              offy=0.;      
00102              stlat1=0.;               
00103              stlat2=0.;      
00104              units="";       
00105              scale=0.;       
00106              pri=0.;         
00107              prj=0.;         
00108              pis=0.;         
00109              pjs=0.;         
00110              prs=0.;         
00111              pscn=0.;        
00112              pyaw=0.;        
00113   }
00114 };
00115 
00116 //========== PROJECTION FACTORY
00118 class TL_DLL TeProjectionFactory 
00119 {
00120 public:
00121   static TeProjection* make( const TeProjectionParams& );
00122   static TeProjection* make(int epsgCode);
00123 };
00124 
00126 
00131 class TL_DLL TeProjection 
00132 {
00133 protected:
00134            string     GPname;                 // projection name
00135            TeDatum GPdatum;             // spheroid
00136            double     GPlon0;                 // Longitude of origin (rad)
00137            double  GPlat0;                    // Latitude of origin (rad)  
00138            double     GPoffx;                 // X (projection coordinate) offset (m)
00139            double     GPoffy;                 // Y (projection coordinate) offset (m)
00140            double     GPstlat1;            // First standard parallel (rad)
00141            double  GPstlat2;            // Second standard parallel (rad)
00142            string  GPunits;             // units
00143            double  GPscale;             // scale (used for UTM)
00144            TeHemisphere  GPhemisphere;  // Hemisphere
00145            TeProjection* GPdestination; // destination projection
00146            int              GPid;          // id
00147     int               GPepsgCode;                      //the epsg code associated to the given projection
00148            TeUnits               GPunitsEnum; //an enum to store the units and used for performance porpouses
00149 
00151 
00168            void       ChangeLL (double &x, double &y); 
00169 
00170 public:
00171 
00173 
00187            TeProjection ( const string& name, const TeDatum& datum,
00188                       double lon0 = 0., double lat0=0., double offx = 0., double offy = 0.,
00189                       double stlat1 = 0., double stlat2 = 0., 
00190                       const string units = "Meters",
00191                       double scale = 1., TeHemisphere hem = TeSOUTH_HEM, int epsgcode = -1):
00192                       GPname   ( name ),
00193                       GPdatum  ( datum ),
00194                GPlon0   ( lon0 ),
00195                GPlat0   ( lat0  ),
00196                GPoffx   ( offx  ),
00197                GPoffy   ( offy ),
00198                GPstlat1 ( stlat1 ),
00199                GPstlat2 ( stlat2 ),
00200                GPunits  ( units ),
00201                GPscale  ( scale ),
00202                GPhemisphere ( hem ),
00203                       GPdestination (0),
00204                       GPid(0),
00205         GPepsgCode(epsgcode)
00206                       {
00207                                  GPunitsEnum = TeGetUnit(units);
00208                       }
00209 
00210                       TeProjection ():
00211                       GPname   ( "NoProjection" ),
00212                GPlon0   ( 0. ),
00213                GPlat0   ( 0. ),
00214                GPoffx   ( 0. ),
00215                GPoffy   ( 0. ),
00216                GPstlat1 ( 0. ),
00217                GPstlat2 ( 0. ),
00218                GPunits  ( "Units" ),
00219                GPscale  ( 1 ),
00220                GPhemisphere ( TeSOUTH_HEM ),
00221                       GPdestination (0),
00222                       GPid(0),
00223                       GPepsgCode(99999),
00224                       GPunitsEnum(TeUndefinedUnit)
00225            {}
00226 
00228            TeProjection(const TeProjection&);
00229 
00231            TeProjection& operator=(const TeProjection&);
00232 
00234            virtual ~TeProjection (){}
00235 
00237            inline string& name() { return GPname; }
00238            
00240   inline const string& name() const { return GPname; } 
00241 
00243            TeDatum datum()
00244            { return GPdatum; }
00245            
00247   inline const TeDatum& datum() const { return GPdatum; }         
00248 
00250            void setDatum(const TeDatum& datum)
00251            {          GPdatum = datum; }
00252 
00254            string& units()
00255            { return GPunits; }
00256 
00258            double     lon0() { return GPlon0;          }
00259            
00261            double  lat0() { return GPlat0;  }            
00262 
00264            double     offX() { return GPoffx; }         
00265     
00267            double     offY() { return GPoffy;           }
00268     
00270            double     stLat1() { return GPstlat1; }
00271            
00273            double  stLat2() { return GPstlat2; }
00274            
00276            double  scale()  { return GPscale;   }
00277            
00278            int epsgCode() { return GPepsgCode; }
00279 
00280            void epsgCode(int code) { GPepsgCode = code; }
00281 
00283            inline const TeHemisphere& hemisphere() const {        return GPhemisphere; }
00284                       
00285            // Returns a the parameters of this projection
00286            virtual TeProjectionParams params () const; //FAMI
00287 
00288            bool operator== (const TeProjection& proj);
00289 
00291 
00304            virtual    TeCoord2D LL2PC (const TeCoord2D& p) = 0;
00305            virtual    void         LL2PC (ostream&) const {} //FAMI
00306 
00308 
00318            virtual    TeCoord2D  PC2LL (const TeCoord2D& p) = 0;
00319 
00320            virtual    void LL2PC (double, double, double&, double&) const {printf("\nWRONG"); return;} //FAMI
00321            virtual    void PC2LL (double, double, double&, double&) {printf("\nWRONG"); return;} //FAMI
00322 
00324            void setDestinationProjection (TeProjection* proj)
00325            { GPdestination = proj; }
00326            
00328            void print ( FILE* file_ );
00329 
00331            string describe ();
00332 
00334            int        id() { return GPid;}
00335 
00337            void id(int i) { GPid = i;}
00338 };
00339 
00340 
00342 
00349 class TL_DLL TeUtm : public TeProjection
00350 {
00351 public:
00352 
00354 
00365            TeUtm ( const TeDatum& datum, double long0, double lat0 = 0., 
00366                            double offx = 500000., double offy = 10000000., 
00367                                   const string& units = "Meters",
00368                                   double scale = 0.9996, TeHemisphere hemisphere = TeSOUTH_HEM );
00370            ~TeUtm () {}
00371 
00373 
00383            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00384 
00386            /*         Projection transforms UTM into geodetic coordinates.
00387                       \param p:  UTM coordinates (m).
00388                       \return p: Geodetic coordinates (rad).
00389                       \note
00390                       X and Y UTM coordinates must be both valid, within
00391                       their typical range. Conventional UTM offsets are
00392                       handled in this method, and therefore must not be 
00393                       previously subtracted.
00394            */
00395            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00396 };
00397 
00399 
00404 class TL_DLL TeLambertConformal : public TeProjection
00405 {
00406 public :
00408 
00419            TeLambertConformal ( const TeDatum& datum, 
00420                                        double long0,
00421                                               double lat0, 
00422                                                                    double offx, 
00423                                                                    double offy,
00424                                                                    double stlat1, 
00425                                                                    double stlat2, 
00426                                                                    const string& units = "Meters" ):
00427            TeProjection ( "LambertConformal", datum, long0, lat0, offx, offy, stlat1, stlat2, units, 1., TeSOUTH_HEM, 9802)
00428            {}
00429 
00431            ~TeLambertConformal () {}
00432 
00433 
00434            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00435 
00436            virtual    TeCoord2D PC2LL(const TeCoord2D& p);
00437 };
00438 
00440 
00444 class TL_DLL TeMercator : public TeProjection
00445 {
00446 
00447 public:
00449 
00459            TeMercator ( const TeDatum& datum,  
00460                                double long0, 
00461                                              double lat0 = 0.,
00462                                              double offx = 0., 
00463                                              double offy = 0.,
00464                                              double stlat1 = 0.,
00465                                              const string& units = "Meters"): 
00466            TeProjection ( "Mercator", datum, long0, lat0, offx, offy, stlat1, 0., units,1., TeSOUTH_HEM, 9805)
00467            {}
00468 
00470            ~TeMercator () {}
00471 
00472            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00473 
00474            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00475 
00476 };
00477 
00478 
00479 
00481 
00486 class TL_DLL TePolyconic : public TeProjection
00487 {
00488 public:
00490 
00499            TePolyconic (const TeDatum& datum,  
00500                                double long0, 
00501                                              double lat0 = 0.,
00502                                              double offx = 0., 
00503                                              double offy = 0.,
00504                                              const string& units = "Meters");
00505            
00507            ~TePolyconic () {}
00508 
00509 
00510            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00511 
00512            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00513 };
00514 
00516 class TL_DLL TeLatLong : public TeProjection
00517 {
00518 
00519 public :
00521 
00526            TeLatLong( const TeDatum& datum, const string& units = "DecimalDegrees" );
00527 
00529            ~TeLatLong () {}
00530 
00532            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00533 
00535            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00536 
00537            virtual void LL2PC(double xi, double yi, double& xo, double& yo) const; //FAMI
00538            virtual void PC2LL(double xi, double yi, double& xo, double& yo); //FAMI
00539 
00540 };
00541 
00543 /*
00544   Specifies methods that are necessary to establish the relation between
00545   geodetic and Albers Conic coordinates. Albers Conic is an equal-area
00546   projection system. 
00547 */
00548 class TL_DLL TeAlbers : public TeProjection
00549 {
00550 public:
00552 
00563            TeAlbers( const TeDatum& datum, 
00564                             double lon0,
00565                                    double lat0, 
00566                                    double offx, 
00567                                    double offy,
00568                                    double stlat1, 
00569                                    double stlat2, 
00570                                    const string& units = "Meters" ):
00571                       TeProjection ( "Albers", datum, lon0, lat0, offx, offy, stlat1, stlat2, units, 1, TeSOUTH_HEM, 9822 )
00572            {} 
00573 
00575            ~TeAlbers () { }
00576 
00577            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00578 
00579            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00580 };
00581 
00583 
00588 class TL_DLL TeMiller : public TeProjection 
00589 {
00590 public:
00592 
00600            TeMiller ( const TeDatum& datum,  
00601                                double long0, 
00602                                              double offx = 0., 
00603                                              double offy = 0.,
00604                                              const string& units = "Meters"): 
00605            TeProjection ( "Miller", datum, long0, 0., offx, offy, 0., 0., units )
00606            {}
00607 
00609            ~TeMiller () {}
00610 
00611            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00612 
00613            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00614 
00615 };
00616 
00618 
00625 class TL_DLL TeSinusoidal : public TeProjection        
00626 {
00627 public:
00628 
00630 
00638            TeSinusoidal (const TeDatum& datum,  
00639                                double long0, 
00640                                              double offx = 0., 
00641                                              double offy = 0.,
00642                                              const string& units = "Meters"): 
00643            TeProjection ( "Sinusoidal", datum, long0, 0., offx, offy, 0., 0., units )
00644            {}
00645 
00647            ~TeSinusoidal () {}
00648 
00649            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00650 
00651            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00652 };
00653 
00655 class TL_DLL TeCylindricalEquidistant : public TeProjection
00656 {
00657 public:
00658 
00660 
00669            TeCylindricalEquidistant (const TeDatum& datum,  
00670                                double lon0, 
00671                                              double offx = 0., 
00672                                              double offy = 0.,
00673                                              double stlat1 = 0.,
00674                                              const string& units = "Meters");
00676            ~TeCylindricalEquidistant () {}
00677 
00678            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00679 
00680            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00681 };
00682 
00684 class TL_DLL TePolarStereographic : public TeProjection
00685 {
00686 public:
00688 
00697            TePolarStereographic ( const TeDatum& datum,  
00698                                double lon0,  
00699                                              double offx = 0., 
00700                                              double offy = 0.,
00701                                              const string& units = "Meters",
00702                                              const TeHemisphere hem = TeSOUTH_HEM );
00703 
00705            ~TePolarStereographic () {}
00706 
00707            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00708            virtual    void       LL2PC (ostream&) const; //FAMI
00709            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00710 
00711            virtual void LL2PC(double xi, double yi, double& xo, double& yo) const; //FAMI
00712 };
00713 
00714 //FAMI
00715 class TL_DLL TeSatelliteProjection : public TeProjection
00716 {
00717 
00718 private:
00719            
00720            double     SPri,      // Sensor angle resolution along y axis in radians
00721                       SPrj,      // Sensor angle resolution along x axis in radians
00722                       SPis,      // Y-coordinate of sub-satellite point 
00723                       SPjs,      // X-coordinate of sub-satellite point
00724                    SPrs,   // Radius of satellite orbit in meters
00725                       SPscn,     // Scanning mode: 0-WE/NS, 1-SN/EW
00726                       SPyaw;  // Grid orientation, i.e., angle in radians between
00727                                  // the increasing y axis and the meridian of the
00728                                  // sub-satellite point along the direction of
00729                                  // increasing latitude.
00730 public:
00731 
00733            /*
00734                       \param datum:         planimetric datum
00735                       \param offx:          x offset
00736                       \param offy:          y offset
00737                       \param Pri:     Sensor angle resolution along y axis in radians
00738                       \param Prj:           Sensor angle resolution along x axis in radians
00739                       \param Pis:     Y-coordinate of sub-satellite point 
00740                       \param Pjs:           X-coordinate of sub-satellite point
00741                       \param Pla0:          Latitude of sub-satellite point in radians
00742                       \param Plo0:          Longitude of sub-satellite point in radians
00743                       \param Prs:           Radius of satellite orbit in meters
00744                       \param Pscn:          Scanning mode: 0-WE/NS, 1-SN/EW
00745                       \param Pyaw:          Grid orientation, i.e., angle in radians between
00746                                             the increasing y axis and the meridian of the
00747                                             sub-satellite point along the direction of
00748                                             increasing latitude.
00749                       */
00750            TeSatelliteProjection(const TeDatum& datum, double offx, double offy,  
00751                                        double Pri, double Prj, double Pis, double Pjs, double Pla0, double Plon0, 
00752                                        double Prs,double Pscn, double Pyaw):
00753                                  TeProjection("Satellite", datum, Plon0, Pla0, offx, offy, 0., 0.,"Meters",1.,TeSOUTH_HEM),
00754                                  SPri(Pri),
00755                                  SPrj(Prj),
00756                                  SPis(Pis),
00757                                  SPjs(Pjs),            
00758                                  SPrs(Prs),
00759                                  SPscn(Pscn),
00760                                  SPyaw(Pyaw)           {}
00761 
00762            ~TeSatelliteProjection() {}
00763 
00764            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00765 
00766            virtual    TeCoord2D PC2LL(const TeCoord2D& p);
00767 
00768            // Returns a the parameters of this projection
00769            virtual TeProjectionParams params () const;
00770 };
00771 
00772 class TL_DLL TeNoProjection : public TeProjection
00773 {
00774 public:
00775            TeNoProjection(const TeDatum& datum = TeDatum(), const string& units = "Units"):
00776                       TeProjection ( "NoProjection", datum, 0., 0., 0., 0., 0, 0, units, 1, TeSOUTH_HEM )
00777 
00778            {          GPname = "NoProjection", GPunits = units; }
00779 
00780                       ~TeNoProjection () {}
00781 
00782                       virtual TeCoord2D LL2PC(const TeCoord2D& p) { return p; }
00783 
00784                       virtual TeCoord2D PC2LL(const TeCoord2D& p) {return p;};
00785 };
00786 
00788 
00793 class TL_DLL TeVirtualEarthMercator : public TeProjection
00794 {
00795 
00796 public:
00798 
00808            TeVirtualEarthMercator ( const TeDatum& datum,  
00809                                double long0, 
00810                                              double lat0 = 0.,
00811                                              double offx = 0., 
00812                                              double offy = 0.,
00813                                              double stlat1 = 0.,
00814                                              const string& units = "Meters"): 
00815            TeProjection ( "VirtualEarthMercator", datum, long0, lat0, offx, offy, stlat1, 0., units )
00816            {}
00817 
00819            ~TeVirtualEarthMercator () {}
00820 
00821            virtual TeCoord2D LL2PC(const TeCoord2D& p);
00822 
00823            virtual TeCoord2D PC2LL(const TeCoord2D& p);
00824 };
00825 
00826 bool TL_DLL decodifyDescription(const string& projDescription, TeProjectionParams& pars);
00827 
00829 /*
00830            \note This function works only for sproj descriptionsgenerated by TerraLib
00831 */
00832 TL_DLL TeProjection* TeGetTeProjectionFromSProj(const string& sproj4desc);
00833 
00835 TL_DLL string TeGetSProjFromTeProjection(TeProjection* teproj);
00836 
00838 TL_DLL string TeGetWKTFromTeProjection(TeProjection* proj);
00839 
00841 /*
00842            \note This function works only for sproj descriptions generated by TerraLib
00843 */
00844 TL_DLL TeProjection* TeGetTeProjectionFromWKT(const string& wkt);
00845 
00851 #endif
00852 
00853 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines