00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QGSCOORDINATEREFERENCESYSTEM_H
00019 #define QGSCOORDINATEREFERENCESYSTEM_H
00020
00021
00022 #include <ostream>
00023
00024
00025 #include <QString>
00026 #include <QMap>
00027 class QDomNode;
00028 class QDomDocument;
00029
00030
00031 typedef struct sqlite3 sqlite3;
00032
00033
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
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
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 ) const;
00208 bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
00215 Q_DECL_DEPRECATED bool equals( QString theProj4String );
00216
00221 bool readXML( QDomNode & theNode );
00239 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
00240
00241
00245 static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
00246
00249 static CUSTOM_CRS_VALIDATION customSrsValidation();
00250
00251
00252
00256 long srsid() const;
00257
00261 long postgisSrid() const;
00262
00267 Q_DECL_DEPRECATED long epsg() const;
00268
00273 QString authid() const;
00274
00279 QString description() const;
00280
00285 QString projectionAcronym() const;
00286
00291 QString ellipsoidAcronym() const;
00292
00296 QString toWkt() const;
00297
00305 QString toProj4() const;
00306
00310 bool geographicFlag() const;
00311
00316 bool axisInverted() const;
00317
00321 QGis::UnitType mapUnits() const;
00322
00323
00324
00327 void setValidationHint( QString html );
00328
00331 QString validationHint();
00337 static int syncDb();
00338
00339
00340
00341
00342 private:
00347 static QString proj4FromSrsId( const int theSrsId );
00348
00352 void setInternalId( long theSrsId );
00356 void setSrid( long theSrid );
00360 void setDescription( QString theDescription );
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 void setProj4String( QString theProj4String );
00375 void setGeographicFlag( bool theGeoFlag );
00376
00380 void setEpsg( long theEpsg );
00381
00385 void setAuthId( QString theID );
00389 void setProjectionAcronym( QString theProjectionAcronym );
00393 void setEllipsoidAcronym( QString theEllipsoidAcronym );
00394
00397 void debugPrint();
00398
00400 typedef QMap<QString, QString> RecordMap;
00407 RecordMap getRecord( QString theSql );
00408
00409
00410
00411 static int openDb( QString path, sqlite3 **db, bool readonly = true );
00412
00414 long mSrsId;
00416 QString mDescription;
00418 QString mProjectionAcronym ;
00420 QString mEllipsoidAcronym;
00422 bool mGeoFlag;
00424 QGis::UnitType mMapUnits;
00426 long mSRID;
00428 QString mAuthId;
00430 bool mIsValidFlag;
00431
00433 void setMapUnits();
00434
00436 bool saveAsUserCRS();
00437
00439 long getRecordCount();
00440
00442 static QString quotedValue( QString value );
00443
00444 void *mCRS;
00445
00446 bool loadFromDb( QString db, QString expression, QString value );
00447
00448 QString mValidationHint;
00449 mutable QString mWkt;
00450
00452 mutable int mAxisInverted;
00453
00454 static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
00455 };
00456
00457
00459 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
00460 {
00461 QString mySummary( "\n\tSpatial Reference System:" );
00462 mySummary += "\n\t\tDescription : ";
00463 if ( !r.description().isNull() )
00464 {
00465 mySummary += r.description();
00466 }
00467 else
00468 {
00469 mySummary += "Undefined" ;
00470 }
00471 mySummary += "\n\t\tProjection : " ;
00472 if ( !r.projectionAcronym().isNull() )
00473 {
00474 mySummary += r.projectionAcronym();
00475 }
00476 else
00477 {
00478 mySummary += "Undefined" ;
00479 }
00480
00481 mySummary += "\n\t\tEllipsoid : ";
00482 if ( !r.ellipsoidAcronym().isNull() )
00483 {
00484 mySummary += r.ellipsoidAcronym();
00485 }
00486 else
00487 {
00488 mySummary += "Undefined" ;
00489 }
00490
00491 mySummary += "\n\t\tProj4String : " ;
00492 if ( !r.toProj4().isNull() )
00493 {
00494 mySummary += r.toProj4();
00495 }
00496 else
00497 {
00498 mySummary += "Undefined" ;
00499 }
00500
00501 return os << mySummary.toLocal8Bit().data() << std::endl;
00502 }
00503
00504 #endif // QGSCOORDINATEREFERENCESYSTEM_H