QGIS API Documentation  2.14.0-Essen
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  //TODO QGIS 3.0 - rename to isGeographic
329  bool geographicFlag() const;
330 
334  bool axisInverted() const;
335 
338  QGis::UnitType mapUnits() const;
339 
340 
341  // Mutators -----------------------------------
344  void setValidationHint( const QString& html );
345 
348  QString validationHint();
353  static int syncDb();
354 
355 
359  bool saveAsUserCRS( const QString& name );
360 
362  QString geographicCRSAuthId() const;
363 
368  static QStringList recentProjections();
369 
370  // Mutators -----------------------------------
371  // We don't want to expose these to the public api since they wont create
372  // a fully valid crs. Programmers should use the createFrom* methods rather
373  private:
378  static QString proj4FromSrsId( const int theSrsId );
379 
383  void setInternalId( long theSrsId );
387  void setSrid( long theSrid );
391  void setDescription( const QString& theDescription );
392 
403  void setProj4String( const QString& theProj4String );
404 
408  void setGeographicFlag( bool theGeoFlag );
409 
413  void setEpsg( long theEpsg );
414 
418  void setAuthId( const QString& theID );
422  void setProjectionAcronym( const QString& theProjectionAcronym );
426  void setEllipsoidAcronym( const QString& theEllipsoidAcronym );
427 
430  void debugPrint();
431 
440  RecordMap getRecord( const QString& theSql );
441 
442  // Open SQLite db and show message if cannot be opened
443  // returns the same code as sqlite3_open
444  static int openDb( const QString& path, sqlite3 **db, bool readonly = true );
445 
447  long mSrsId;
449  QString mDescription;
451  QString mProjectionAcronym;
453  QString mEllipsoidAcronym;
455  bool mGeoFlag;
457  QGis::UnitType mMapUnits;
459  long mSRID;
461  QString mAuthId;
463  bool mIsValidFlag;
464 
466  void setMapUnits();
467 
469  long getRecordCount();
470 
472  static QString quotedValue( QString value );
473 
475 
476  bool loadFromDb( const QString& db, const QString& expression, const QString& value );
477 
478  QString mValidationHint;
479  mutable QString mWkt;
480  mutable QString mProj4;
481 
482  static bool loadIDs( QHash<int, QString> &wkts );
483  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
484  static bool syncDatumTransform( const QString& dbPath );
485 
487  mutable int mAxisInverted;
488 
489  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
490 };
491 
492 
494 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
495 {
496  QString mySummary( "\n\tSpatial Reference System:" );
497  mySummary += "\n\t\tDescription : ";
498  if ( !r.description().isNull() )
499  {
500  mySummary += r.description();
501  }
502  else
503  {
504  mySummary += "Undefined";
505  }
506  mySummary += "\n\t\tProjection : ";
507  if ( !r.projectionAcronym().isNull() )
508  {
509  mySummary += r.projectionAcronym();
510  }
511  else
512  {
513  mySummary += "Undefined";
514  }
515 
516  mySummary += "\n\t\tEllipsoid : ";
517  if ( !r.ellipsoidAcronym().isNull() )
518  {
519  mySummary += r.ellipsoidAcronym();
520  }
521  else
522  {
523  mySummary += "Undefined";
524  }
525 
526  mySummary += "\n\t\tProj4String : ";
527  if ( !r.toProj4().isNull() )
528  {
529  mySummary += r.toProj4();
530  }
531  else
532  {
533  mySummary += "Undefined";
534  }
535  // Using streams we need to use local 8 Bit
536  return os << mySummary.toLocal8Bit().data() << std::endl;
537 }
538 
539 #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.