Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 QgsCoordinateTransform.h - Coordinate Transforms 00003 ------------------- 00004 begin : Dec 2004 00005 copyright : (C) 2004 Tim Sutton 00006 email : tim at linfiniti.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 /* $Id$ */ 00018 #ifndef QGSCOORDINATETRANSFORM_H 00019 #define QGSCOORDINATETRANSFORM_H 00020 00021 //qt includes 00022 #include <QObject> 00023 00024 //qgis includes 00025 #include "qgspoint.h" 00026 #include "qgsrectangle.h" 00027 #include "qgscsexception.h" 00028 #include "qgscoordinatereferencesystem.h" 00029 class QDomNode; 00030 class QDomDocument; 00031 00032 //non qt includes 00033 #include <iostream> 00034 #include <vector> 00035 00036 typedef void* projPJ; 00037 class QString; 00038 00052 class CORE_EXPORT QgsCoordinateTransform: public QObject 00053 { 00054 Q_OBJECT 00055 public: 00057 QgsCoordinateTransform() ; 00058 00063 QgsCoordinateTransform( const QgsCoordinateReferenceSystem& theSource, 00064 const QgsCoordinateReferenceSystem& theDest ); 00065 00067 QgsCoordinateTransform( long theSourceSrsId, long theDestSrsId ); 00068 00075 QgsCoordinateTransform( QString theSourceWkt, QString theDestWkt ); 00076 00084 QgsCoordinateTransform( long theSourceSrid, 00085 QString theDestWkt, 00086 QgsCoordinateReferenceSystem::CrsType theSourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId ); 00087 00089 ~QgsCoordinateTransform(); 00090 00092 enum TransformDirection 00093 { 00094 ForwardTransform, 00095 ReverseTransform 00096 }; 00097 00102 void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS ); 00103 00108 void setDestCRS( const QgsCoordinateReferenceSystem& theCRS ); 00109 00114 const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; } 00115 00120 const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; } 00121 00129 QgsPoint transform( const QgsPoint p, TransformDirection direction = ForwardTransform ) const; 00130 00139 QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const; 00140 00151 QgsRectangle transformBoundingBox( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const; 00152 00153 // Same as for the other transform() functions, but alters the x 00154 // and y variables in place. The second one works with good old-fashioned 00155 // C style arrays. 00156 void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const; 00157 00158 void transformInPlace( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z, 00159 TransformDirection direction = ForwardTransform ) const; 00160 00168 QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const; 00169 00180 void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const; 00181 00186 bool isInitialised() const {return mInitialisedFlag;}; 00187 00191 bool isShortCircuited() {return mShortCircuit;}; 00192 00202 void setDestCRSID( long theCRSID ); 00203 00204 public slots: 00206 void initialise(); 00207 00212 bool readXML( QDomNode & theNode ); 00213 00219 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00220 00221 signals: 00223 void invalidTransformInput() const; 00224 00225 private: 00226 00231 bool mShortCircuit; 00232 00236 bool mInitialisedFlag; 00237 00241 QgsCoordinateReferenceSystem mSourceCRS; 00242 00246 QgsCoordinateReferenceSystem mDestCRS; 00247 00251 projPJ mSourceProjection; 00252 00256 projPJ mDestinationProjection; 00257 00261 void setFinder(); 00262 }; 00263 00265 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r ) 00266 { 00267 QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ); 00268 mySummary += "\n\tInitialised? : "; 00269 //prevent warnings 00270 if ( r.isInitialised() ) 00271 { 00272 //do nothing this is a dummy 00273 } 00274 00275 #if 0 00276 if ( r.isInitialised() ) 00277 { 00278 mySummary += "Yes"; 00279 } 00280 else 00281 { 00282 mySummary += "No" ; 00283 } 00284 mySummary += "\n\tShort Circuit? : " ; 00285 if ( r.isShortCircuited() ) 00286 { 00287 mySummary += "Yes"; 00288 } 00289 else 00290 { 00291 mySummary += "No" ; 00292 } 00293 00294 mySummary += "\n\tSource Spatial Ref Sys : "; 00295 if ( r.sourceCrs() ) 00296 { 00297 mySummary << r.sourceCrs(); 00298 } 00299 else 00300 { 00301 mySummary += "Undefined" ; 00302 } 00303 00304 mySummary += "\n\tDest Spatial Ref Sys : " ; 00305 if ( r.destCRS() ) 00306 { 00307 mySummary << r.destCRS(); 00308 } 00309 else 00310 { 00311 mySummary += "Undefined" ; 00312 } 00313 #endif 00314 00315 mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" ); 00316 return os << mySummary.toLocal8Bit().data() << std::endl; 00317 } 00318 00319 00320 #endif // QGSCOORDINATETRANSFORM_H