OGR

ogr_spatialref.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: ogr_spatialref.h 21467 2011-01-12 20:19:38Z warmerdam $
00003  *
00004  * Project:  OpenGIS Simple Features Reference Implementation
00005  * Purpose:  Classes for manipulating spatial reference systems in a
00006  *           platform non-specific manner.
00007  * Author:   Frank Warmerdam, warmerdam@pobox.com
00008  *
00009  ******************************************************************************
00010  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00028  * DEALINGS IN THE SOFTWARE.
00029  ****************************************************************************/
00030 
00031 #ifndef _OGR_SPATIALREF_H_INCLUDED
00032 #define _OGR_SPATIALREF_H_INCLUDED
00033 
00034 #include "ogr_srs_api.h"
00035 
00042 /************************************************************************/
00043 /*                             OGR_SRSNode                              */
00044 /************************************************************************/
00045 
00059 class CPL_DLL OGR_SRSNode
00060 {
00061     char        *pszValue;
00062 
00063     OGR_SRSNode **papoChildNodes;
00064     OGR_SRSNode *poParent;
00065 
00066     int         nChildren;
00067 
00068     void        ClearChildren();
00069     int         NeedsQuoting() const;
00070     
00071   public:
00072                 OGR_SRSNode(const char * = NULL);
00073                 ~OGR_SRSNode();
00074 
00075     int         IsLeafNode() const { return nChildren == 0; }
00076     
00077     int         GetChildCount() const { return nChildren; }
00078     OGR_SRSNode *GetChild( int );
00079     const OGR_SRSNode *GetChild( int ) const;
00080 
00081     OGR_SRSNode *GetNode( const char * );
00082     const OGR_SRSNode *GetNode( const char * ) const;
00083 
00084     void        InsertChild( OGR_SRSNode *, int );
00085     void        AddChild( OGR_SRSNode * );
00086     int         FindChild( const char * ) const;
00087     void        DestroyChild( int );
00088     void        StripNodes( const char * );
00089 
00090     const char  *GetValue() const { return pszValue; }
00091     void        SetValue( const char * );
00092 
00093     void        MakeValueSafe();
00094     OGRErr      FixupOrdering();
00095 
00096     OGR_SRSNode *Clone() const;
00097 
00098     OGRErr      importFromWkt( char ** );
00099     OGRErr      exportToWkt( char ** ) const;
00100     OGRErr      exportToPrettyWkt( char **, int = 1) const;
00101     
00102     OGRErr      applyRemapper( const char *pszNode, 
00103                                char **papszSrcValues, 
00104                                char **papszDstValues, 
00105                                int nStepSize = 1,
00106                                int bChildOfHit = FALSE );
00107 };
00108 
00109 /************************************************************************/
00110 /*                         OGRSpatialReference                          */
00111 /************************************************************************/
00112 
00127 class CPL_DLL OGRSpatialReference
00128 {
00129     double      dfFromGreenwich;
00130     double      dfToMeter;
00131     double      dfToDegrees;
00132 
00133     OGR_SRSNode *poRoot;
00134 
00135     int         nRefCount;
00136     int         bNormInfoSet;
00137 
00138     static OGRErr Validate(OGR_SRSNode *poRoot);
00139     static OGRErr ValidateAuthority(OGR_SRSNode *poRoot);
00140     static OGRErr ValidateAxis(OGR_SRSNode *poRoot);
00141     static OGRErr ValidateUnit(OGR_SRSNode *poRoot);
00142     static OGRErr ValidateVertDatum(OGR_SRSNode *poRoot);
00143     static OGRErr ValidateProjection( OGR_SRSNode* poRoot );
00144     static int  IsAliasFor( const char *, const char * );
00145     void        GetNormInfo() const;
00146 
00147   public:
00148                 OGRSpatialReference(const OGRSpatialReference&);
00149                 OGRSpatialReference(const char * = NULL);
00150                 
00151     virtual    ~OGRSpatialReference();
00152     
00153     static void DestroySpatialReference(OGRSpatialReference* poSRS);
00154                 
00155     OGRSpatialReference &operator=(const OGRSpatialReference&);
00156 
00157     int         Reference();
00158     int         Dereference();
00159     int         GetReferenceCount() const { return nRefCount; }
00160     void        Release();
00161 
00162     OGRSpatialReference *Clone() const;
00163     OGRSpatialReference *CloneGeogCS() const;
00164 
00165     OGRErr      exportToWkt( char ** ) const;
00166     OGRErr      exportToPrettyWkt( char **, int = FALSE) const;
00167     OGRErr      exportToProj4( char ** ) const;
00168     OGRErr      exportToPCI( char **, char **, double ** ) const;
00169     OGRErr      exportToUSGS( long *, long *, double **, long * ) const;
00170     OGRErr      exportToXML( char **, const char * = NULL ) const;
00171     OGRErr      exportToPanorama( long *, long *, long *, long *,
00172                                   double * ) const;
00173     OGRErr      exportToERM( char *pszProj, char *pszDatum, char *pszUnits );
00174     OGRErr      exportToMICoordSys( char ** ) const;
00175     
00176     OGRErr      importFromWkt( char ** );
00177     OGRErr      importFromProj4( const char * );
00178     OGRErr      importFromEPSG( int );
00179     OGRErr      importFromEPSGA( int );
00180     OGRErr      importFromESRI( char ** );
00181     OGRErr      importFromPCI( const char *, const char * = NULL,
00182                                double * = NULL );
00183     OGRErr      importFromUSGS( long iProjSys, long iZone,
00184                                 double *padfPrjParams,
00185                                 long iDatum, int bAnglesInPackedDMSFormat = TRUE );
00186     OGRErr      importFromPanorama( long, long, long, double* );
00187     OGRErr      importFromOzi( const char *, const char *, const char * );
00188     OGRErr      importFromWMSAUTO( const char *pszAutoDef );
00189     OGRErr      importFromXML( const char * );
00190     OGRErr      importFromDict( const char *pszDict, const char *pszCode );
00191     OGRErr      importFromURN( const char * );
00192     OGRErr      importFromERM( const char *pszProj, const char *pszDatum,
00193                                const char *pszUnits );
00194     OGRErr      importFromUrl( const char * );
00195     OGRErr      importFromMICoordSys( const char * );
00196     
00197     OGRErr      morphToESRI();
00198     OGRErr      morphFromESRI();
00199 
00200     OGRErr      Validate();
00201     OGRErr      StripCTParms( OGR_SRSNode * = NULL );
00202     OGRErr      StripVertical();
00203     OGRErr      FixupOrdering();
00204     OGRErr      Fixup();
00205 
00206     int         EPSGTreatsAsLatLong();
00207     const char *GetAxis( const char *pszTargetKey, int iAxis, 
00208                          OGRAxisOrientation *peOrientation ) const;
00209     OGRErr      SetAxes( const char *pszTargetKey, 
00210                          const char *pszXAxisName, 
00211                          OGRAxisOrientation eXAxisOrientation,
00212                          const char *pszYAxisName, 
00213                          OGRAxisOrientation eYAxisOrientation );
00214 
00215     // Machinary for accessing parse nodes
00216     OGR_SRSNode *GetRoot() { return poRoot; }
00217     const OGR_SRSNode *GetRoot() const { return poRoot; }
00218     void        SetRoot( OGR_SRSNode * );
00219     
00220     OGR_SRSNode *GetAttrNode(const char *);
00221     const OGR_SRSNode *GetAttrNode(const char *) const;
00222     const char  *GetAttrValue(const char *, int = 0) const;
00223 
00224     OGRErr      SetNode( const char *, const char * );
00225     OGRErr      SetNode( const char *, double );
00226 
00227     OGRErr      SetLinearUnitsAndUpdateParameters( const char *pszName, 
00228                                                    double dfInMeters );
00229     OGRErr      SetLinearUnits( const char *pszName, double dfInMeters );
00230     double      GetLinearUnits( char ** = NULL ) const;
00231 
00232     OGRErr      SetAngularUnits( const char *pszName, double dfInRadians );
00233     double      GetAngularUnits( char ** = NULL ) const;
00234 
00235     double      GetPrimeMeridian( char ** = NULL ) const;
00236 
00237     int         IsGeographic() const;
00238     int         IsProjected() const;
00239     int         IsLocal() const;
00240     int         IsVertical() const;
00241     int         IsSameGeogCS( const OGRSpatialReference * ) const;
00242     int         IsSameVertCS( const OGRSpatialReference * ) const;
00243     int         IsSame( const OGRSpatialReference * ) const;
00244 
00245     void        Clear();
00246     OGRErr      SetLocalCS( const char * );
00247     OGRErr      SetProjCS( const char * );
00248     OGRErr      SetProjection( const char * );
00249     OGRErr      SetGeogCS( const char * pszGeogName,
00250                            const char * pszDatumName,
00251                            const char * pszEllipsoidName,
00252                            double dfSemiMajor, double dfInvFlattening,
00253                            const char * pszPMName = NULL,
00254                            double dfPMOffset = 0.0,
00255                            const char * pszUnits = NULL,
00256                            double dfConvertToRadians = 0.0 );
00257     OGRErr      SetWellKnownGeogCS( const char * );
00258     OGRErr      CopyGeogCSFrom( const OGRSpatialReference * poSrcSRS );
00259 
00260     OGRErr      SetFromUserInput( const char * );
00261 
00262     OGRErr      SetTOWGS84( double, double, double,
00263                             double = 0.0, double = 0.0, double = 0.0,
00264                             double = 0.0 );
00265     OGRErr      GetTOWGS84( double *padfCoef, int nCoeff = 7 ) const;
00266     
00267     double      GetSemiMajor( OGRErr * = NULL ) const;
00268     double      GetSemiMinor( OGRErr * = NULL ) const;
00269     double      GetInvFlattening( OGRErr * = NULL ) const;
00270 
00271     OGRErr      SetAuthority( const char * pszTargetKey, 
00272                               const char * pszAuthority, 
00273                               int nCode );
00274 
00275     OGRErr      AutoIdentifyEPSG();
00276     int         GetEPSGGeogCS();
00277 
00278     const char *GetAuthorityCode( const char * pszTargetKey ) const;
00279     const char *GetAuthorityName( const char * pszTargetKey ) const;
00280 
00281     const char *GetExtension( const char *pszTargetKey, 
00282                               const char *pszName,
00283                               const char *pszDefault = NULL ) const;
00284     OGRErr      SetExtension( const char *pszTargetKey, 
00285                               const char *pszName, 
00286                               const char *pszValue );
00287     
00288     int         FindProjParm( const char *pszParameter,
00289                               const OGR_SRSNode *poPROJCS=NULL ) const;
00290     OGRErr      SetProjParm( const char *, double );
00291     double      GetProjParm( const char *, double =0.0, OGRErr* = NULL ) const;
00292 
00293     OGRErr      SetNormProjParm( const char *, double );
00294     double      GetNormProjParm( const char *, double=0.0, OGRErr* =NULL)const;
00295 
00296     static int  IsAngularParameter( const char * );
00297     static int  IsLongitudeParameter( const char * );
00298     static int  IsLinearParameter( const char * );
00299 
00301     OGRErr      SetACEA( double dfStdP1, double dfStdP2,
00302                          double dfCenterLat, double dfCenterLong,
00303                          double dfFalseEasting, double dfFalseNorthing );
00304     
00306     OGRErr      SetAE( double dfCenterLat, double dfCenterLong,
00307                        double dfFalseEasting, double dfFalseNorthing );
00308 
00310     OGRErr      SetBonne( double dfStdP1, double dfCentralMeridian,
00311                           double dfFalseEasting, double dfFalseNorthing );
00312     
00314     OGRErr      SetCEA( double dfStdP1, double dfCentralMeridian,
00315                         double dfFalseEasting, double dfFalseNorthing );
00316 
00318     OGRErr      SetCS( double dfCenterLat, double dfCenterLong,
00319                        double dfFalseEasting, double dfFalseNorthing );
00320 
00322     OGRErr      SetEC( double dfStdP1, double dfStdP2,
00323                        double dfCenterLat, double dfCenterLong,
00324                        double dfFalseEasting, double dfFalseNorthing );
00325 
00327     OGRErr      SetEckert( int nVariation, double dfCentralMeridian,
00328                            double dfFalseEasting, double dfFalseNorthing );
00329 
00330     OGRErr      SetEckertIV( double dfCentralMeridian,
00331                              double dfFalseEasting, double dfFalseNorthing );
00332 
00333     OGRErr      SetEckertVI( double dfCentralMeridian,
00334                              double dfFalseEasting, double dfFalseNorthing );
00335 
00337     OGRErr      SetEquirectangular(double dfCenterLat, double dfCenterLong,
00338                             double dfFalseEasting, double dfFalseNorthing );
00340     OGRErr      SetEquirectangular2( double dfCenterLat, double dfCenterLong,
00341                                      double dfPseudoStdParallel1,
00342                                      double dfFalseEasting, double dfFalseNorthing );
00343 
00345     OGRErr      SetGEOS( double dfCentralMeridian, double dfSatelliteHeight, 
00346                          double dfFalseEasting, double dfFalseNorthing );
00347 
00349     OGRErr      SetGH( double dfCentralMeridian, 
00350                        double dfFalseEasting, double dfFalseNorthing );
00351 
00353     OGRErr      SetGS( double dfCentralMeridian,
00354                        double dfFalseEasting, double dfFalseNorthing );
00355  
00357     OGRErr      SetGaussSchreiberTMercator(double dfCenterLat, double dfCenterLong,
00358                                            double dfScale,
00359                                            double dfFalseEasting, double dfFalseNorthing );
00360 
00362     OGRErr      SetGnomonic(double dfCenterLat, double dfCenterLong,
00363                             double dfFalseEasting, double dfFalseNorthing );
00364 
00366     OGRErr      SetHOM( double dfCenterLat, double dfCenterLong,
00367                         double dfAzimuth, double dfRectToSkew,
00368                         double dfScale,
00369                         double dfFalseEasting, double dfFalseNorthing );
00370 
00371     OGRErr      SetHOM2PNO( double dfCenterLat,
00372                             double dfLat1, double dfLong1,
00373                             double dfLat2, double dfLong2,
00374                             double dfScale,
00375                             double dfFalseEasting, double dfFalseNorthing );
00376 
00378     OGRErr      SetIWMPolyconic( double dfLat1, double dfLat2,
00379                                  double dfCenterLong,
00380                                  double dfFalseEasting,
00381                                  double dfFalseNorthing );
00382 
00384     OGRErr      SetKrovak( double dfCenterLat, double dfCenterLong,
00385                            double dfAzimuth, double dfPseudoStdParallelLat,
00386                            double dfScale, 
00387                            double dfFalseEasting, double dfFalseNorthing );
00388 
00390     OGRErr      SetLAEA( double dfCenterLat, double dfCenterLong,
00391                          double dfFalseEasting, double dfFalseNorthing );
00392 
00394     OGRErr      SetLCC( double dfStdP1, double dfStdP2,
00395                         double dfCenterLat, double dfCenterLong,
00396                         double dfFalseEasting, double dfFalseNorthing );
00397 
00399     OGRErr      SetLCC1SP( double dfCenterLat, double dfCenterLong,
00400                            double dfScale,
00401                            double dfFalseEasting, double dfFalseNorthing );
00402 
00404     OGRErr      SetLCCB( double dfStdP1, double dfStdP2,
00405                          double dfCenterLat, double dfCenterLong,
00406                          double dfFalseEasting, double dfFalseNorthing );
00407     
00409     OGRErr      SetMC( double dfCenterLat, double dfCenterLong,
00410                        double dfFalseEasting, double dfFalseNorthing );
00411 
00413     OGRErr      SetMercator( double dfCenterLat, double dfCenterLong,
00414                              double dfScale, 
00415                              double dfFalseEasting, double dfFalseNorthing );
00416 
00417     OGRErr      SetMercator2SP( double dfStdP1,
00418                                 double dfCenterLat, double dfCenterLong,
00419                                 double dfFalseEasting, double dfFalseNorthing );
00420 
00422     OGRErr      SetMollweide( double dfCentralMeridian,
00423                               double dfFalseEasting, double dfFalseNorthing );
00424 
00426     OGRErr      SetNZMG( double dfCenterLat, double dfCenterLong,
00427                          double dfFalseEasting, double dfFalseNorthing );
00428 
00430     OGRErr      SetOS( double dfOriginLat, double dfCMeridian,
00431                        double dfScale,
00432                        double dfFalseEasting,double dfFalseNorthing);
00433     
00435     OGRErr      SetOrthographic( double dfCenterLat, double dfCenterLong,
00436                                  double dfFalseEasting,double dfFalseNorthing);
00437 
00439     OGRErr      SetPolyconic( double dfCenterLat, double dfCenterLong,
00440                               double dfFalseEasting, double dfFalseNorthing );
00441 
00443     OGRErr      SetPS( double dfCenterLat, double dfCenterLong,
00444                        double dfScale,
00445                        double dfFalseEasting, double dfFalseNorthing);
00446     
00448     OGRErr      SetRobinson( double dfCenterLong, 
00449                              double dfFalseEasting, double dfFalseNorthing );
00450     
00452     OGRErr      SetSinusoidal( double dfCenterLong, 
00453                                double dfFalseEasting, double dfFalseNorthing );
00454     
00456     OGRErr      SetStereographic( double dfCenterLat, double dfCenterLong,
00457                                   double dfScale,
00458                                  double dfFalseEasting,double dfFalseNorthing);
00459 
00461     OGRErr      SetSOC( double dfLatitudeOfOrigin, double dfCentralMeridian,
00462                         double dfFalseEasting, double dfFalseNorthing );
00463     
00465     OGRErr      SetTM( double dfCenterLat, double dfCenterLong,
00466                        double dfScale,
00467                        double dfFalseEasting, double dfFalseNorthing );
00468 
00470     OGRErr      SetTMVariant( const char *pszVariantName, 
00471                               double dfCenterLat, double dfCenterLong,
00472                               double dfScale,
00473                               double dfFalseEasting, double dfFalseNorthing );
00474 
00476     OGRErr      SetTMG( double dfCenterLat, double dfCenterLong, 
00477                         double dfFalseEasting, double dfFalseNorthing );
00478 
00480     OGRErr      SetTMSO( double dfCenterLat, double dfCenterLong,
00481                          double dfScale,
00482                          double dfFalseEasting, double dfFalseNorthing );
00483 
00485     OGRErr      SetTPED( double dfLat1, double dfLong1, 
00486                          double dfLat2, double dfLong2, 
00487                          double dfFalseEasting, double dfFalseNorthing );
00488     
00490     OGRErr      SetVDG( double dfCenterLong,
00491                         double dfFalseEasting, double dfFalseNorthing );
00492 
00494     OGRErr      SetUTM( int nZone, int bNorth = TRUE );
00495     int         GetUTMZone( int *pbNorth = NULL ) const;
00496 
00498     OGRErr      SetWagner( int nVariation, double dfCenterLat,
00499                            double dfFalseEasting, double dfFalseNorthing );
00500 
00502     OGRErr      SetStatePlane( int nZone, int bNAD83 = TRUE,
00503                                const char *pszOverrideUnitName = NULL,
00504                                double dfOverrideUnit = 0.0 );
00505 };
00506 
00507 /************************************************************************/
00508 /*                     OGRCoordinateTransformation                      */
00509 /*                                                                      */
00510 /*      This is really just used as a base class for a private          */
00511 /*      implementation.                                                 */
00512 /************************************************************************/
00513 
00523 class CPL_DLL OGRCoordinateTransformation
00524 {
00525 public:
00526     virtual ~OGRCoordinateTransformation() {}
00527     
00528     static void DestroyCT(OGRCoordinateTransformation* poCT);
00529 
00530     // From CT_CoordinateTransformation
00531 
00533     virtual OGRSpatialReference *GetSourceCS() = 0;
00534 
00536     virtual OGRSpatialReference *GetTargetCS() = 0;
00537 
00538     // From CT_MathTransform
00539 
00555     virtual int Transform( int nCount, 
00556                            double *x, double *y, double *z = NULL ) = 0;
00557 
00573     virtual int TransformEx( int nCount, 
00574                              double *x, double *y, double *z = NULL,
00575                              int *pabSuccess = NULL ) = 0;
00576 
00577 };
00578 
00579 OGRCoordinateTransformation CPL_DLL *
00580 OGRCreateCoordinateTransformation( OGRSpatialReference *poSource, 
00581                                    OGRSpatialReference *poTarget );
00582 
00583 #endif /* ndef _OGR_SPATIALREF_H_INCLUDED */

Generated for GDAL by doxygen 1.7.3.