QGIS API Documentation  2.13.0-Master
qgscoordinatereferencesystem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscoordinatereferencesystem.h
3 
4  -------------------
5  begin : 2007
6  copyright : (C) 2007 by Gary E. Sherman
7  email : [email protected]
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #ifndef QGSCOORDINATEREFERENCESYSTEM_H
19 #define QGSCOORDINATEREFERENCESYSTEM_H
20 
21 //Standard includes
22 #include <ostream>
23 
24 //qt includes
25 #include <QString>
26 #include <QMap>
27 #include <QHash>
28 
29 class QDomNode;
30 class QDomDocument;
31 
32 // forward declaration for sqlite3
33 typedef struct sqlite3 sqlite3;
34 
35 //qgis includes
36 #include "qgis.h"
37 
38 #ifdef DEBUG
39 typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
40 #else
41 typedef void *OGRSpatialReferenceH;
42 #endif
43 
46 
51 {
52  public:
53 
54  enum CrsType
55  {
58  EpsgCrsId // deprecated
59  };
60 
63 
65 
71  explicit QgsCoordinateReferenceSystem( const QString& theDefinition );
72 
80  QgsCoordinateReferenceSystem( const long theId, CrsType theType = PostgisCrsId );
81 
84 
87 
88  // Misc helper functions -----------------------
89 
90  bool createFromId( const long theId, CrsType theType = PostgisCrsId );
91 
99  bool createFromOgcWmsCrs( QString theCrs );
100 
107  bool createFromSrid( const long theSrid );
108 
119  bool createFromWkt( const QString &theWkt );
120 
129  bool createFromSrsId( const long theSrsId );
130 
157  bool createFromProj4( const QString &theProjString );
158 
166  bool createFromString( const QString &theDefinition );
167 
181  bool createFromUserInput( const QString &theDefinition );
182 
191  static void setupESRIWktFix();
192 
194  bool isValid() const;
195 
205  void validate();
206 
218  long findMatchingProj();
219 
223  bool operator==( const QgsCoordinateReferenceSystem &theSrs ) const;
227  bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
228 
233  bool readXML( const QDomNode & theNode );
251  bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
252 
253 
258  static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
259 
263  static CUSTOM_CRS_VALIDATION customSrsValidation();
264 
265  // Accessors -----------------------------------
266 
271  long srsid() const;
272 
276  long postgisSrid() const;
277 
284  QString authid() const;
285 
293  QString description() const;
294 
300  QString projectionAcronym() const;
301 
307  QString ellipsoidAcronym() const;
308 
313  QString toWkt() const;
314 
323  QString toProj4() const;
324 
328  bool geographicFlag() const;
329 
333  bool axisInverted() const;
334 
337  QGis::UnitType mapUnits() const;
338 
339 
340  // Mutators -----------------------------------
343  void setValidationHint( const QString& html );
344 
347  QString validationHint();
352  static int syncDb();
353 
354 
358  bool saveAsUserCRS( const QString& name );
359 
361  QString geographicCRSAuthId() const;
362 
367  static QStringList recentProjections();
368 
369  // Mutators -----------------------------------
370  // We don't want to expose these to the public api since they wont create
371  // a fully valid crs. Programmers should use the createFrom* methods rather
372  private:
377  static QString proj4FromSrsId( const int theSrsId );
378 
382  void setInternalId( long theSrsId );
386  void setSrid( long theSrid );
390  void setDescription( const QString& theDescription );
391 
402  void setProj4String( const QString& theProj4String );
403 
407  void setGeographicFlag( bool theGeoFlag );
408 
412  void setEpsg( long theEpsg );
413 
417  void setAuthId( const QString& theID );
421  void setProjectionAcronym( const QString& theProjectionAcronym );
425  void setEllipsoidAcronym( const QString& theEllipsoidAcronym );
426 
429  void debugPrint();
430 
439  RecordMap getRecord( const QString& theSql );
440 
441  // Open SQLite db and show message if cannot be opened
442  // returns the same code as sqlite3_open
443  static int openDb( const QString& path, sqlite3 **db, bool readonly = true );
444 
446  long mSrsId;
448  QString mDescription;
450  QString mProjectionAcronym;
452  QString mEllipsoidAcronym;
454  bool mGeoFlag;
456  QGis::UnitType mMapUnits;
458  long mSRID;
460  QString mAuthId;
462  bool mIsValidFlag;
463 
465  void setMapUnits();
466 
468  long getRecordCount();
469 
471  static QString quotedValue( QString value );
472 
474 
475  bool loadFromDb( const QString& db, const QString& expression, const QString& value );
476 
477  QString mValidationHint;
478  mutable QString mWkt;
479  mutable QString mProj4;
480 
481  static bool loadIDs( QHash<int, QString> &wkts );
482  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
483  static bool syncDatumTransform( const QString& dbPath );
484 
486  mutable int mAxisInverted;
487 
488  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
489 };
490 
491 
493 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
494 {
495  QString mySummary( "\n\tSpatial Reference System:" );
496  mySummary += "\n\t\tDescription : ";
497  if ( !r.description().isNull() )
498  {
499  mySummary += r.description();
500  }
501  else
502  {
503  mySummary += "Undefined";
504  }
505  mySummary += "\n\t\tProjection : ";
506  if ( !r.projectionAcronym().isNull() )
507  {
508  mySummary += r.projectionAcronym();
509  }
510  else
511  {
512  mySummary += "Undefined";
513  }
514 
515  mySummary += "\n\t\tEllipsoid : ";
516  if ( !r.ellipsoidAcronym().isNull() )
517  {
518  mySummary += r.ellipsoidAcronym();
519  }
520  else
521  {
522  mySummary += "Undefined";
523  }
524 
525  mySummary += "\n\t\tProj4String : ";
526  if ( !r.toProj4().isNull() )
527  {
528  mySummary += r.toProj4();
529  }
530  else
531  {
532  mySummary += "Undefined";
533  }
534  // Using streams we need to use local 8 Bit
535  return os << mySummary.toLocal8Bit().data() << std::endl;
536 }
537 
538 #endif // QGSCOORDINATEREFERENCESYSTEM_H
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool isNull() const
std::ostream & operator<<(std::ostream &os, const QgsCoordinateReferenceSystem &r)
Output stream operator.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
QByteArray toLocal8Bit() const
struct sqlite3 sqlite3
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
Class for storing a coordinate reference system (CRS)
UnitType
Map units that qgis supports.
Definition: qgis.h:155
char * data()
QString description() const
Returns the descriptive name of the CRS, eg "WGS 84" or "GDA 94 / Vicgrid94".
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
void * OGRSpatialReferenceH
QString toProj4() const
Returns a Proj4 string representation of this CRS.