Quantum GIS API Documentation  1.8
src/core/qgscoordinatereferencesystem.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                              qgscoordinatereferencesystem.h
00003 
00004                              -------------------
00005     begin                : 2007
00006     copyright            : (C) 2007 by Gary E. Sherman
00007     email                : [email protected]
00008 ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 #ifndef QGSCOORDINATEREFERENCESYSTEM_H
00019 #define QGSCOORDINATEREFERENCESYSTEM_H
00020 
00021 //Standard includes
00022 #include <ostream>
00023 
00024 //qt includes
00025 #include <QString>
00026 #include <QMap>
00027 class QDomNode;
00028 class QDomDocument;
00029 
00030 // forward declaration for sqlite3
00031 typedef struct sqlite3 sqlite3;
00032 
00033 //qgis includes
00034 #include "qgis.h"
00035 
00036 class QgsCoordinateReferenceSystem;
00037 typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem* );
00038 
00039 
00043 class CORE_EXPORT QgsCoordinateReferenceSystem
00044 {
00045   public:
00046 
00047     enum CrsType
00048     {
00049       InternalCrsId,
00050       PostgisCrsId,
00051       EpsgCrsId  // deprecated
00052     };
00053 
00055     QgsCoordinateReferenceSystem();
00056 
00057     ~QgsCoordinateReferenceSystem();
00058 
00064     explicit QgsCoordinateReferenceSystem( QString theDefinition );
00065 
00073     QgsCoordinateReferenceSystem( const long theId, CrsType theType = PostgisCrsId );
00074 
00076     QgsCoordinateReferenceSystem( const QgsCoordinateReferenceSystem& srs );
00077 
00079     QgsCoordinateReferenceSystem& operator=( const QgsCoordinateReferenceSystem& srs );
00080 
00081     // Misc helper functions -----------------------
00082 
00083     bool createFromId( const long theId, CrsType theType = PostgisCrsId );
00084 
00092     bool createFromOgcWmsCrs( QString theCrs );
00093 
00100     bool createFromSrid( const long theSrid );
00101 
00112     bool createFromWkt( const QString theWkt );
00113 
00122     Q_DECL_DEPRECATED bool createFromEpsg( const long theEpsg );
00123 
00132     bool createFromSrsId( const long theSrsId );
00133 
00163     bool createFromProj4( const QString theProjString );
00164 
00172     bool createFromString( const QString theDefinition );
00173 
00187     bool createFromUserInput( const QString theDefinition );
00188 
00198     static void setupESRIWktFix();
00199 
00201     bool isValid() const;
00202 
00212     void validate();
00213 
00225     long findMatchingProj();
00226 
00230     bool operator==( const QgsCoordinateReferenceSystem &theSrs ) const;
00234     bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
00241     Q_DECL_DEPRECATED bool equals( QString theProj4String );
00242 
00247     bool readXML( QDomNode & theNode );
00265     bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
00266 
00267 
00271     static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
00272 
00275     static CUSTOM_CRS_VALIDATION customSrsValidation();
00276 
00277     // Accessors -----------------------------------
00278 
00282     long srsid() const;
00283 
00287     long postgisSrid() const;
00288 
00293     Q_DECL_DEPRECATED long epsg() const;
00294 
00299     QString authid() const;
00300 
00305     QString description() const;
00306 
00311     QString projectionAcronym() const;
00312 
00317     QString ellipsoidAcronym() const;
00318 
00322     QString toWkt() const;
00323 
00331     QString toProj4() const;
00332 
00336     bool geographicFlag() const;
00337 
00342     bool axisInverted() const;
00343 
00347     QGis::UnitType mapUnits() const;
00348 
00349 
00350     // Mutators -----------------------------------
00353     void setValidationHint( QString html );
00354 
00357     QString validationHint();
00363     static int syncDb();
00364 
00365     // Mutators -----------------------------------
00366     // We don't want to expose these to the public api since they wont create
00367     // a fully valid crs. Programmers should use the createFrom* methods rather
00368   private:
00373     static QString proj4FromSrsId( const int theSrsId );
00374 
00378     void setInternalId( long theSrsId );
00382     void setSrid( long theSrid );
00386     void setDescription( QString theDescription );
00387     /* Set the Proj Proj4String.
00388      * @param  QString theProj4String Proj4 format specifies
00389      * (excluding proj and ellips) that define this srs.
00390      * @note some content of the PROJ4 string may be stripped off by this
00391      * method due to the parsing of the string by OSRNewSpatialReference .
00392      * For example input:
00393      * +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
00394      * Gets stored in the CRS as:
00395      * +proj=longlat +datum=WGS84 +no_defs
00396      */
00397     void setProj4String( QString theProj4String );
00401     void setGeographicFlag( bool theGeoFlag );
00402 
00406     void setEpsg( long theEpsg );
00407 
00411     void setAuthId( QString theID );
00415     void setProjectionAcronym( QString theProjectionAcronym );
00419     void setEllipsoidAcronym( QString theEllipsoidAcronym );
00420 
00423     void debugPrint();
00424 
00426     typedef QMap<QString, QString> RecordMap;
00433     RecordMap getRecord( QString theSql );
00434 
00435     // Open SQLite db and show message if cannot be opened
00436     // returns the same code as sqlite3_open
00437     static int openDb( QString path, sqlite3 **db, bool readonly = true );
00438 
00440     long    mSrsId;
00442     QString mDescription;
00444     QString mProjectionAcronym ;
00446     QString mEllipsoidAcronym;
00448     bool    mGeoFlag;
00450     QGis::UnitType mMapUnits;
00452     long    mSRID;
00454     QString mAuthId;
00456     bool mIsValidFlag;
00457 
00459     void setMapUnits();
00460 
00462     bool saveAsUserCRS();
00463 
00465     long getRecordCount();
00466 
00468     static QString quotedValue( QString value );
00469 
00470     void *mCRS;
00471 
00472     bool loadFromDb( QString db, QString expression, QString value );
00473 
00474     QString mValidationHint;
00475     mutable QString mWkt;
00476 
00478     mutable int mAxisInverted;
00479 
00480     static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
00481 };
00482 
00483 
00485 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
00486 {
00487   QString mySummary( "\n\tSpatial Reference System:" );
00488   mySummary += "\n\t\tDescription : ";
00489   if ( !r.description().isNull() )
00490   {
00491     mySummary += r.description();
00492   }
00493   else
00494   {
00495     mySummary += "Undefined" ;
00496   }
00497   mySummary += "\n\t\tProjection  : " ;
00498   if ( !r.projectionAcronym().isNull() )
00499   {
00500     mySummary += r.projectionAcronym();
00501   }
00502   else
00503   {
00504     mySummary += "Undefined" ;
00505   }
00506 
00507   mySummary += "\n\t\tEllipsoid   : ";
00508   if ( !r.ellipsoidAcronym().isNull() )
00509   {
00510     mySummary += r.ellipsoidAcronym();
00511   }
00512   else
00513   {
00514     mySummary += "Undefined" ;
00515   }
00516 
00517   mySummary += "\n\t\tProj4String  : " ;
00518   if ( !r.toProj4().isNull() )
00519   {
00520     mySummary += r.toProj4();
00521   }
00522   else
00523   {
00524     mySummary += "Undefined" ;
00525   }
00526   // Using streams we need to use local 8 Bit
00527   return os << mySummary.toLocal8Bit().data() << std::endl;
00528 }
00529 
00530 #endif // QGSCOORDINATEREFERENCESYSTEM_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines