Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgscoordinatereferencesystem.h 00003 00004 ------------------- 00005 begin : 2007 00006 copyright : (C) 2007 by Gary E. Sherman 00007 email : sherman@mrcc.com 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 00175 bool isValid() const; 00176 00186 void validate(); 00187 00199 long findMatchingProj(); 00200 00204 bool operator==( const QgsCoordinateReferenceSystem &theSrs ); 00208 bool operator!=( const QgsCoordinateReferenceSystem &theSrs ); 00214 bool equals( QString theProj4String ); 00215 00220 bool readXML( QDomNode & theNode ); 00238 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const; 00239 00240 00244 static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f ); 00245 00248 static CUSTOM_CRS_VALIDATION customSrsValidation(); 00249 00250 // Accessors ----------------------------------- 00251 00255 long srsid() const; 00256 00260 long postgisSrid() const; 00261 00266 Q_DECL_DEPRECATED long epsg() const; 00267 00272 QString authid() const; 00273 00278 QString description() const; 00279 00284 QString projectionAcronym() const; 00285 00290 QString ellipsoidAcronym() const; 00291 00295 QString toWkt() const; 00296 00304 QString toProj4() const; 00305 00309 bool geographicFlag() const; 00310 00314 QGis::UnitType mapUnits() const; 00315 00316 00317 // Mutators ----------------------------------- 00320 void setValidationHint( QString html ); 00321 00324 QString validationHint(); 00325 // Mutators ----------------------------------- 00326 // We don't want to expose these to the public api since they wont create 00327 // a fully valid crs. Programmers should use the createFrom* methods rather 00328 private: 00333 static QString proj4FromSrsId( const int theSrsId ); 00334 00338 void setInternalId( long theSrsId ); 00342 void setSrid( long theSrid ); 00346 void setDescription( QString theDescription ); 00347 /* Set the Proj Proj4String. 00348 * @param QString theProj4String Proj4 format specifies (excluding proj and ellips) that define this srs. 00349 */ 00350 void setProj4String( QString theProj4String ); 00354 void setGeographicFlag( bool theGeoFlag ); 00355 00359 void setEpsg( long theEpsg ); 00360 00364 void setAuthId( QString theID ); 00368 void setProjectionAcronym( QString theProjectionAcronym ); 00372 void setEllipsoidAcronym( QString theEllipsoidAcronym ); 00373 00376 void debugPrint(); 00377 00379 typedef QMap<QString, QString> RecordMap; 00386 RecordMap getRecord( QString theSql ); 00387 00388 // Open SQLite db and show message if ccannot be opened 00389 // returns the same code as sqlite3_open 00390 static int openDb( QString path, sqlite3 **db ); 00391 00393 long mSrsId; 00395 QString mDescription; 00397 QString mProjectionAcronym ; 00399 QString mEllipsoidAcronym; 00401 bool mGeoFlag; 00403 QGis::UnitType mMapUnits; 00405 long mSRID; 00407 QString mAuthId; 00409 bool mIsValidFlag; 00410 00412 void setMapUnits(); 00413 00415 bool saveAsUserCRS(); 00416 00418 long getRecordCount(); 00419 00421 QString quotedValue( QString value ); 00422 00423 void *mCRS; 00424 00425 bool loadFromDb( QString db, QString expression, QString value ); 00426 00427 QString mValidationHint; 00428 00429 static CUSTOM_CRS_VALIDATION mCustomSrsValidation; 00430 }; 00431 00432 00434 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r ) 00435 { 00436 QString mySummary( "\n\tSpatial Reference System:" ); 00437 mySummary += "\n\t\tDescription : "; 00438 if ( !r.description().isNull() ) 00439 { 00440 mySummary += r.description(); 00441 } 00442 else 00443 { 00444 mySummary += "Undefined" ; 00445 } 00446 mySummary += "\n\t\tProjection : " ; 00447 if ( !r.projectionAcronym().isNull() ) 00448 { 00449 mySummary += r.projectionAcronym(); 00450 } 00451 else 00452 { 00453 mySummary += "Undefined" ; 00454 } 00455 00456 mySummary += "\n\t\tEllipsoid : "; 00457 if ( !r.ellipsoidAcronym().isNull() ) 00458 { 00459 mySummary += r.ellipsoidAcronym(); 00460 } 00461 else 00462 { 00463 mySummary += "Undefined" ; 00464 } 00465 00466 mySummary += "\n\t\tProj4String : " ; 00467 if ( !r.toProj4().isNull() ) 00468 { 00469 mySummary += r.toProj4(); 00470 } 00471 else 00472 { 00473 mySummary += "Undefined" ; 00474 } 00475 // Using streams we need to use local 8 Bit 00476 return os << mySummary.toLocal8Bit().data() << std::endl; 00477 } 00478 00479 #endif // QGSCOORDINATEREFERENCESYSTEM_H