QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 : sherman@mrcc.com
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( 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( 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 
270  long srsid() const;
271 
275  long postgisSrid() const;
276 
280  QString authid() const;
281 
286  QString description() const;
287 
292  QString projectionAcronym() const;
293 
298  QString ellipsoidAcronym() const;
299 
303  QString toWkt() const;
304 
312  QString toProj4() const;
313 
317  bool geographicFlag() const;
318 
322  bool axisInverted() const;
323 
327  QGis::UnitType mapUnits() const;
328 
329 
330  // Mutators -----------------------------------
333  void setValidationHint( QString html );
334 
337  QString validationHint();
342  static int syncDb();
343 
344 
348  bool saveAsUserCRS( QString name );
349 
351  QString geographicCRSAuthId() const;
352 
357  static QStringList recentProjections();
358 
359  // Mutators -----------------------------------
360  // We don't want to expose these to the public api since they wont create
361  // a fully valid crs. Programmers should use the createFrom* methods rather
362  private:
367  static QString proj4FromSrsId( const int theSrsId );
368 
372  void setInternalId( long theSrsId );
376  void setSrid( long theSrid );
380  void setDescription( QString theDescription );
381 
392  void setProj4String( QString theProj4String );
393 
397  void setGeographicFlag( bool theGeoFlag );
398 
402  void setEpsg( long theEpsg );
403 
407  void setAuthId( QString theID );
411  void setProjectionAcronym( QString theProjectionAcronym );
415  void setEllipsoidAcronym( QString theEllipsoidAcronym );
416 
419  void debugPrint();
420 
422  typedef QMap<QString, QString> RecordMap;
429  RecordMap getRecord( QString theSql );
430 
431  // Open SQLite db and show message if cannot be opened
432  // returns the same code as sqlite3_open
433  static int openDb( QString path, sqlite3 **db, bool readonly = true );
434 
436  long mSrsId;
438  QString mDescription;
440  QString mProjectionAcronym;
442  QString mEllipsoidAcronym;
444  bool mGeoFlag;
446  QGis::UnitType mMapUnits;
448  long mSRID;
450  QString mAuthId;
452  bool mIsValidFlag;
453 
455  void setMapUnits();
456 
458  long getRecordCount();
459 
461  static QString quotedValue( QString value );
462 
464 
465  bool loadFromDb( QString db, QString expression, QString value );
466 
467  QString mValidationHint;
468  mutable QString mWkt;
469  mutable QString mProj4;
470 
471  static bool loadIDs( QHash<int, QString> &wkts );
472  static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
473  static bool syncDatumTransform( const QString& dbPath );
474 
476  mutable int mAxisInverted;
477 
478  static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
479 };
480 
481 
483 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
484 {
485  QString mySummary( "\n\tSpatial Reference System:" );
486  mySummary += "\n\t\tDescription : ";
487  if ( !r.description().isNull() )
488  {
489  mySummary += r.description();
490  }
491  else
492  {
493  mySummary += "Undefined";
494  }
495  mySummary += "\n\t\tProjection : ";
496  if ( !r.projectionAcronym().isNull() )
497  {
498  mySummary += r.projectionAcronym();
499  }
500  else
501  {
502  mySummary += "Undefined";
503  }
504 
505  mySummary += "\n\t\tEllipsoid : ";
506  if ( !r.ellipsoidAcronym().isNull() )
507  {
508  mySummary += r.ellipsoidAcronym();
509  }
510  else
511  {
512  mySummary += "Undefined";
513  }
514 
515  mySummary += "\n\t\tProj4String : ";
516  if ( !r.toProj4().isNull() )
517  {
518  mySummary += r.toProj4();
519  }
520  else
521  {
522  mySummary += "Undefined";
523  }
524  // Using streams we need to use local 8 Bit
525  return os << mySummary.toLocal8Bit().data() << std::endl;
526 }
527 
528 #endif // QGSCOORDINATEREFERENCESYSTEM_H
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
UnitType
Map units that qgis supports.
Definition: qgis.h:229
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
Get the Ellipsoid Acronym.
QByteArray toLocal8Bit() const
struct sqlite3 sqlite3
QString projectionAcronym() const
Get the Projection Acronym.
Class for storing a coordinate reference system (CRS)
char * data()
QString description() const
Get the Description.
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
void * OGRSpatialReferenceH
QString toProj4() const
Get the Proj Proj4 string representation of this srs.