QGIS API Documentation  2.17.0-Master (f49f7ce)
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 class QgsCoordinateReferenceSystemPrivate;
32 
33 // forward declaration for sqlite3
34 typedef struct sqlite3 sqlite3;
35 
36 //qgis includes
37 #include "qgis.h"
38 
39 #ifdef DEBUG
40 typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
41 #else
42 typedef void *OGRSpatialReferenceH;
43 #endif
44 
47 
53 {
54  public:
55 
56  enum CrsType
57  {
60  EpsgCrsId // deprecated
61  };
62 
64 
66 
72  explicit QgsCoordinateReferenceSystem( const QString& theDefinition );
73 
81  QgsCoordinateReferenceSystem( const long theId, CrsType theType = PostgisCrsId );
82 
85 
88 
89  // Misc helper functions -----------------------
90 
91  bool createFromId( const long theId, CrsType theType = PostgisCrsId );
92 
98  bool createFromOgcWmsCrs( const QString& theCrs );
99 
106  bool createFromSrid( const long theSrid );
107 
119  bool createFromWkt( const QString &theWkt );
120 
130  bool createFromSrsId( const long theSrsId );
131 
159  bool createFromProj4( const QString &theProjString );
160 
168  bool createFromString( const QString &theDefinition );
169 
183  bool createFromUserInput( const QString &theDefinition );
184 
193  static void setupESRIWktFix();
194 
196  bool isValid() const;
197 
207  void validate();
208 
220  long findMatchingProj();
221 
225  bool operator==( const QgsCoordinateReferenceSystem &theSrs ) const;
229  bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
230 
235  bool readXML( const QDomNode & theNode );
253  bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
254 
255 
260  static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
261 
265  static CUSTOM_CRS_VALIDATION customSrsValidation();
266 
267  // Accessors -----------------------------------
268 
273  long srsid() const;
274 
278  long postgisSrid() const;
279 
286  QString authid() const;
287 
295  QString description() const;
296 
302  QString projectionAcronym() const;
303 
309  QString ellipsoidAcronym() const;
310 
315  QString toWkt() const;
316 
325  QString toProj4() const;
326 
330  //TODO QGIS 3.0 - rename to isGeographic
331  bool geographicFlag() const;
332 
336  bool axisInverted() const;
337 
340  QGis::UnitType mapUnits() const;
341 
342 
343  // Mutators -----------------------------------
346  void setValidationHint( const QString& html );
347 
350  QString validationHint();
355  static int syncDb();
356 
357 
361  bool saveAsUserCRS( const QString& name );
362 
364  QString geographicCRSAuthId() const;
365 
370  static QStringList recentProjections();
371 
372  // Mutators -----------------------------------
373  // We don't want to expose these to the public api since they wont create
374  // a fully valid crs. Programmers should use the createFrom* methods rather
375  private:
380  static QString proj4FromSrsId( const int theSrsId );
381 
385  void setInternalId( long theSrsId );
389  void setSrid( long theSrid );
393  void setDescription( const QString& theDescription );
394 
405  void setProj4String( const QString& theProj4String );
406 
410  void setGeographicFlag( bool theGeoFlag );
411 
415  void setEpsg( long theEpsg );
416 
420  void setAuthId( const QString& theID );
424  void setProjectionAcronym( const QString& theProjectionAcronym );
428  void setEllipsoidAcronym( const QString& theEllipsoidAcronym );
429 
432  void debugPrint();
433 
442  RecordMap getRecord( const QString& theSql );
443 
444  // Open SQLite db and show message if cannot be opened
445  // returns the same code as sqlite3_open
446  static int openDb( const QString& path, sqlite3 **db, bool readonly = true );
447 
449  void setMapUnits();
450 
452  long getRecordCount();
453 
455  static QString quotedValue( QString value );
456 
457  bool loadFromDb( const QString& db, const QString& expression, const QString& value );
458 
459  static bool loadIDs( QHash<int, QString> &wkts );
460  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
461  static bool syncDatumTransform( const QString& dbPath );
462 
464 
465  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
466 };
467 
468 
470 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
471 {
472  QString mySummary( "\n\tSpatial Reference System:" );
473  mySummary += "\n\t\tDescription : ";
474  if ( !r.description().isNull() )
475  {
476  mySummary += r.description();
477  }
478  else
479  {
480  mySummary += "Undefined";
481  }
482  mySummary += "\n\t\tProjection : ";
483  if ( !r.projectionAcronym().isNull() )
484  {
485  mySummary += r.projectionAcronym();
486  }
487  else
488  {
489  mySummary += "Undefined";
490  }
491 
492  mySummary += "\n\t\tEllipsoid : ";
493  if ( !r.ellipsoidAcronym().isNull() )
494  {
495  mySummary += r.ellipsoidAcronym();
496  }
497  else
498  {
499  mySummary += "Undefined";
500  }
501 
502  mySummary += "\n\t\tProj4String : ";
503  if ( !r.toProj4().isNull() )
504  {
505  mySummary += r.toProj4();
506  }
507  else
508  {
509  mySummary += "Undefined";
510  }
511  // Using streams we need to use local 8 Bit
512  return os << mySummary.toLocal8Bit().data() << std::endl;
513 }
514 
515 #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:159
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.