QGIS API Documentation  2.15.0-Master (af20121)
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 
100  bool createFromOgcWmsCrs( const QString& theCrs );
101 
108  bool createFromSrid( const long theSrid );
109 
120  bool createFromWkt( const QString &theWkt );
121 
130  bool createFromSrsId( const long theSrsId );
131 
158  bool createFromProj4( const QString &theProjString );
159 
167  bool createFromString( const QString &theDefinition );
168 
182  bool createFromUserInput( const QString &theDefinition );
183 
192  static void setupESRIWktFix();
193 
195  bool isValid() const;
196 
206  void validate();
207 
219  long findMatchingProj();
220 
224  bool operator==( const QgsCoordinateReferenceSystem &theSrs ) const;
228  bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
229 
234  bool readXML( const QDomNode & theNode );
252  bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
253 
254 
259  static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
260 
264  static CUSTOM_CRS_VALIDATION customSrsValidation();
265 
266  // Accessors -----------------------------------
267 
272  long srsid() const;
273 
277  long postgisSrid() const;
278 
285  QString authid() const;
286 
294  QString description() const;
295 
301  QString projectionAcronym() const;
302 
308  QString ellipsoidAcronym() const;
309 
314  QString toWkt() const;
315 
324  QString toProj4() const;
325 
329  //TODO QGIS 3.0 - rename to isGeographic
330  bool geographicFlag() const;
331 
335  bool axisInverted() const;
336 
339  QGis::UnitType mapUnits() const;
340 
341 
342  // Mutators -----------------------------------
345  void setValidationHint( const QString& html );
346 
349  QString validationHint();
354  static int syncDb();
355 
356 
360  bool saveAsUserCRS( const QString& name );
361 
363  QString geographicCRSAuthId() const;
364 
369  static QStringList recentProjections();
370 
371  // Mutators -----------------------------------
372  // We don't want to expose these to the public api since they wont create
373  // a fully valid crs. Programmers should use the createFrom* methods rather
374  private:
379  static QString proj4FromSrsId( const int theSrsId );
380 
384  void setInternalId( long theSrsId );
388  void setSrid( long theSrid );
392  void setDescription( const QString& theDescription );
393 
404  void setProj4String( const QString& theProj4String );
405 
409  void setGeographicFlag( bool theGeoFlag );
410 
414  void setEpsg( long theEpsg );
415 
419  void setAuthId( const QString& theID );
423  void setProjectionAcronym( const QString& theProjectionAcronym );
427  void setEllipsoidAcronym( const QString& theEllipsoidAcronym );
428 
431  void debugPrint();
432 
441  RecordMap getRecord( const QString& theSql );
442 
443  // Open SQLite db and show message if cannot be opened
444  // returns the same code as sqlite3_open
445  static int openDb( const QString& path, sqlite3 **db, bool readonly = true );
446 
448  void setMapUnits();
449 
451  long getRecordCount();
452 
454  static QString quotedValue( QString value );
455 
456  bool loadFromDb( const QString& db, const QString& expression, const QString& value );
457 
458  static bool loadIDs( QHash<int, QString> &wkts );
459  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
460  static bool syncDatumTransform( const QString& dbPath );
461 
463 
464  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
465 };
466 
467 
469 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
470 {
471  QString mySummary( "\n\tSpatial Reference System:" );
472  mySummary += "\n\t\tDescription : ";
473  if ( !r.description().isNull() )
474  {
475  mySummary += r.description();
476  }
477  else
478  {
479  mySummary += "Undefined";
480  }
481  mySummary += "\n\t\tProjection : ";
482  if ( !r.projectionAcronym().isNull() )
483  {
484  mySummary += r.projectionAcronym();
485  }
486  else
487  {
488  mySummary += "Undefined";
489  }
490 
491  mySummary += "\n\t\tEllipsoid : ";
492  if ( !r.ellipsoidAcronym().isNull() )
493  {
494  mySummary += r.ellipsoidAcronym();
495  }
496  else
497  {
498  mySummary += "Undefined";
499  }
500 
501  mySummary += "\n\t\tProj4String : ";
502  if ( !r.toProj4().isNull() )
503  {
504  mySummary += r.toProj4();
505  }
506  else
507  {
508  mySummary += "Undefined";
509  }
510  // Using streams we need to use local 8 Bit
511  return os << mySummary.toLocal8Bit().data() << std::endl;
512 }
513 
514 #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.