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
00063 explicit QgsCoordinateReferenceSystem( QString theWkt );
00064
00072 QgsCoordinateReferenceSystem( const long theId, CrsType theType = PostgisCrsId );
00073
00075 QgsCoordinateReferenceSystem( const QgsCoordinateReferenceSystem& srs );
00076
00078 QgsCoordinateReferenceSystem& operator=( const QgsCoordinateReferenceSystem& srs );
00079
00080
00081
00082 void createFromId( const long theId, CrsType theType = PostgisCrsId );
00083
00093 bool createFromOgcWmsCrs( QString theCrs );
00094
00101 bool createFromSrid( const long theSrid );
00102
00113 bool createFromWkt( const QString theWkt );
00114
00122 bool createFromEpsg( const long theEpsg );
00123
00132 bool createFromSrsId( const long theSrsId );
00133
00163 bool createFromProj4( const QString theProjString );
00164
00166 bool isValid() const;
00167
00177 void validate();
00178
00190 long findMatchingProj();
00191
00195 bool operator==( const QgsCoordinateReferenceSystem &theSrs );
00199 bool operator!=( const QgsCoordinateReferenceSystem &theSrs );
00205 bool equals( QString theProj4String );
00206
00211 bool readXML( QDomNode & theNode );
00229 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
00230
00231
00235 static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
00236
00239 static CUSTOM_CRS_VALIDATION customSrsValidation();
00240
00241
00242
00246 long srsid() const;
00247
00251 long postgisSrid() const;
00252
00256 long epsg() const;
00257
00262 QString authid() const;
00263
00268 QString description() const;
00269
00274 QString projectionAcronym() const;
00275
00280 QString ellipsoidAcronym() const;
00281
00285 QString toWkt() const;
00286
00294 QString toProj4() const;
00295
00299 bool geographicFlag() const;
00300
00304 QGis::UnitType mapUnits() const;
00305
00306
00307
00310 void setValidationHint( QString html );
00311
00314 QString validationHint();
00315
00316
00317
00318 private:
00323 static QString proj4FromSrsId( const int theSrsId );
00324
00328 void setInternalId( long theSrsId );
00332 void setSrid( long theSrid );
00336 void setDescription( QString theDescription );
00337
00338
00339
00340 void setProj4String( QString theProj4String );
00344 void setGeographicFlag( bool theGeoFlag );
00345
00349 void setEpsg( long theEpsg );
00350
00354 void setAuthId( QString theID );
00358 void setProjectionAcronym( QString theProjectionAcronym );
00362 void setEllipsoidAcronym( QString theEllipsoidAcronym );
00363
00366 void debugPrint();
00367
00369 typedef QMap<QString, QString> RecordMap;
00376 RecordMap getRecord( QString theSql );
00377
00378
00379
00380 static int openDb( QString path, sqlite3 **db );
00381
00383 long mSrsId;
00385 QString mDescription;
00387 QString mProjectionAcronym ;
00389 QString mEllipsoidAcronym;
00391 bool mGeoFlag;
00393 QGis::UnitType mMapUnits;
00395 long mSRID;
00397 QString mAuthId;
00399 bool mIsValidFlag;
00400
00402 void setMapUnits();
00403
00405 bool saveAsUserCRS();
00406
00408 long getRecordCount();
00409
00411 QString quotedValue( QString value );
00412
00413 void *mCRS;
00414
00415 bool loadFromDb( QString db, QString expression, QString value );
00416
00417 QString mValidationHint;
00418
00419 static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
00420 };
00421
00422
00424 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
00425 {
00426 QString mySummary( "\n\tSpatial Reference System:" );
00427 mySummary += "\n\t\tDescription : ";
00428 if ( !r.description().isNull() )
00429 {
00430 mySummary += r.description();
00431 }
00432 else
00433 {
00434 mySummary += "Undefined" ;
00435 }
00436 mySummary += "\n\t\tProjection : " ;
00437 if ( !r.projectionAcronym().isNull() )
00438 {
00439 mySummary += r.projectionAcronym();
00440 }
00441 else
00442 {
00443 mySummary += "Undefined" ;
00444 }
00445
00446 mySummary += "\n\t\tEllipsoid : ";
00447 if ( !r.ellipsoidAcronym().isNull() )
00448 {
00449 mySummary += r.ellipsoidAcronym();
00450 }
00451 else
00452 {
00453 mySummary += "Undefined" ;
00454 }
00455
00456 mySummary += "\n\t\tProj4String : " ;
00457 if ( !r.toProj4().isNull() )
00458 {
00459 mySummary += r.toProj4();
00460 }
00461 else
00462 {
00463 mySummary += "Undefined" ;
00464 }
00465
00466 return os << mySummary.toLocal8Bit().data() << std::endl;
00467 }
00468
00469 #endif // QGSCOORDINATEREFERENCESYSTEM_H