Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 class QDomNode;
28 class QDomDocument;
29 
30 // forward declaration for sqlite3
31 typedef struct sqlite3 sqlite3;
32 
33 //qgis includes
34 #include "qgis.h"
35 
38 
39 
44 {
45  public:
46 
47  enum CrsType
48  {
51  EpsgCrsId // deprecated
52  };
53 
56 
58 
64  explicit QgsCoordinateReferenceSystem( QString theDefinition );
65 
73  QgsCoordinateReferenceSystem( const long theId, CrsType theType = PostgisCrsId );
74 
77 
80 
81  // Misc helper functions -----------------------
82 
83  bool createFromId( const long theId, CrsType theType = PostgisCrsId );
84 
92  bool createFromOgcWmsCrs( QString theCrs );
93 
100  bool createFromSrid( const long theSrid );
101 
112  bool createFromWkt( const QString theWkt );
113 
122  Q_DECL_DEPRECATED bool createFromEpsg( const long theEpsg );
123 
132  bool createFromSrsId( const long theSrsId );
133 
163  bool createFromProj4( const QString theProjString );
164 
172  bool createFromString( const QString theDefinition );
173 
175  bool isValid() const;
176 
186  void validate();
187 
199  long findMatchingProj();
200 
204  bool operator==( const QgsCoordinateReferenceSystem &theSrs );
208  bool operator!=( const QgsCoordinateReferenceSystem &theSrs );
214  bool equals( QString theProj4String );
215 
220  bool readXML( QDomNode & theNode );
238  bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
239 
240 
244  static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
245 
248  static CUSTOM_CRS_VALIDATION customSrsValidation();
249 
250  // Accessors -----------------------------------
251 
255  long srsid() const;
256 
260  long postgisSrid() const;
261 
266  Q_DECL_DEPRECATED long epsg() const;
267 
272  QString authid() const;
273 
278  QString description() const;
279 
284  QString projectionAcronym() const;
285 
290  QString ellipsoidAcronym() const;
291 
295  QString toWkt() const;
296 
304  QString toProj4() const;
305 
309  bool geographicFlag() const;
310 
314  QGis::UnitType mapUnits() const;
315 
316 
317  // Mutators -----------------------------------
320  void setValidationHint( QString html );
321 
324  QString validationHint();
325  // Mutators -----------------------------------
326  // We don't want to expose these to the public api since they wont create
327  // a fully valid crs. Programmers should use the createFrom* methods rather
328  private:
333  static QString proj4FromSrsId( const int theSrsId );
334 
338  void setInternalId( long theSrsId );
342  void setSrid( long theSrid );
346  void setDescription( QString theDescription );
347  /* Set the Proj Proj4String.
348  * @param QString theProj4String Proj4 format specifies (excluding proj and ellips) that define this srs.
349  */
350  void setProj4String( QString theProj4String );
354  void setGeographicFlag( bool theGeoFlag );
355 
359  void setEpsg( long theEpsg );
360 
364  void setAuthId( QString theID );
368  void setProjectionAcronym( QString theProjectionAcronym );
372  void setEllipsoidAcronym( QString theEllipsoidAcronym );
373 
376  void debugPrint();
377 
379  typedef QMap<QString, QString> RecordMap;
386  RecordMap getRecord( QString theSql );
387 
388  // Open SQLite db and show message if ccannot be opened
389  // returns the same code as sqlite3_open
390  static int openDb( QString path, sqlite3 **db );
391 
393  long mSrsId;
395  QString mDescription;
401  bool mGeoFlag;
405  long mSRID;
407  QString mAuthId;
410 
412  void setMapUnits();
413 
415  bool saveAsUserCRS();
416 
418  long getRecordCount();
419 
421  QString quotedValue( QString value );
422 
423  void *mCRS;
424 
425  bool loadFromDb( QString db, QString expression, QString value );
426 
428 
430 };
431 
432 
434 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateReferenceSystem &r )
435 {
436  QString mySummary( "\n\tSpatial Reference System:" );
437  mySummary += "\n\t\tDescription : ";
438  if ( !r.description().isNull() )
439  {
440  mySummary += r.description();
441  }
442  else
443  {
444  mySummary += "Undefined" ;
445  }
446  mySummary += "\n\t\tProjection : " ;
447  if ( !r.projectionAcronym().isNull() )
448  {
449  mySummary += r.projectionAcronym();
450  }
451  else
452  {
453  mySummary += "Undefined" ;
454  }
455 
456  mySummary += "\n\t\tEllipsoid : ";
457  if ( !r.ellipsoidAcronym().isNull() )
458  {
459  mySummary += r.ellipsoidAcronym();
460  }
461  else
462  {
463  mySummary += "Undefined" ;
464  }
465 
466  mySummary += "\n\t\tProj4String : " ;
467  if ( !r.toProj4().isNull() )
468  {
469  mySummary += r.toProj4();
470  }
471  else
472  {
473  mySummary += "Undefined" ;
474  }
475  // Using streams we need to use local 8 Bit
476  return os << mySummary.toLocal8Bit().data() << std::endl;
477 }
478 
479 #endif // QGSCOORDINATEREFERENCESYSTEM_H