QGIS API Documentation  2.15.0-Master (972fc9f)
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 
118  bool createFromWkt( const QString &theWkt );
119 
128  bool createFromSrsId( const long theSrsId );
129 
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  void setMapUnits();
448 
450  long getRecordCount();
451 
453  static QString quotedValue( QString value );
454 
455  bool loadFromDb( const QString& db, const QString& expression, const QString& value );
456 
457  static bool loadIDs( QHash<int, QString> &wkts );
458  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
459  static bool syncDatumTransform( const QString& dbPath );
460 
462 
463  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
464 };
465 
466 
468 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
469 {
470  QString mySummary( "\n\tSpatial Reference System:" );
471  mySummary += "\n\t\tDescription : ";
472  if ( !r.description().isNull() )
473  {
474  mySummary += r.description();
475  }
476  else
477  {
478  mySummary += "Undefined";
479  }
480  mySummary += "\n\t\tProjection : ";
481  if ( !r.projectionAcronym().isNull() )
482  {
483  mySummary += r.projectionAcronym();
484  }
485  else
486  {
487  mySummary += "Undefined";
488  }
489 
490  mySummary += "\n\t\tEllipsoid : ";
491  if ( !r.ellipsoidAcronym().isNull() )
492  {
493  mySummary += r.ellipsoidAcronym();
494  }
495  else
496  {
497  mySummary += "Undefined";
498  }
499 
500  mySummary += "\n\t\tProj4String : ";
501  if ( !r.toProj4().isNull() )
502  {
503  mySummary += r.toProj4();
504  }
505  else
506  {
507  mySummary += "Undefined";
508  }
509  // Using streams we need to use local 8 Bit
510  return os << mySummary.toLocal8Bit().data() << std::endl;
511 }
512 
513 #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.