Quantum GIS API Documentation
1.8
|
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 #ifndef QGSCOORDINATETRANSFORM_H 00018 #define QGSCOORDINATETRANSFORM_H 00019 00020 //qt includes 00021 #include <QObject> 00022 00023 //qgis includes 00024 #include "qgspoint.h" 00025 #include "qgsrectangle.h" 00026 #include "qgscsexception.h" 00027 #include "qgscoordinatereferencesystem.h" 00028 class QDomNode; 00029 class QDomDocument; 00030 00031 //non qt includes 00032 #include <iostream> 00033 #include <vector> 00034 00035 typedef void* projPJ; 00036 class QString; 00037 00051 class CORE_EXPORT QgsCoordinateTransform: public QObject 00052 { 00053 Q_OBJECT 00054 public: 00056 QgsCoordinateTransform() ; 00057 00062 QgsCoordinateTransform( const QgsCoordinateReferenceSystem& theSource, 00063 const QgsCoordinateReferenceSystem& theDest ); 00064 00066 QgsCoordinateTransform( long theSourceSrsId, long theDestSrsId ); 00067 00074 QgsCoordinateTransform( QString theSourceWkt, QString theDestWkt ); 00075 00083 QgsCoordinateTransform( long theSourceSrid, 00084 QString theDestWkt, 00085 QgsCoordinateReferenceSystem::CrsType theSourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId ); 00086 00088 ~QgsCoordinateTransform(); 00089 00091 enum TransformDirection 00092 { 00093 ForwardTransform, 00094 ReverseTransform 00095 }; 00096 00101 void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS ); 00102 00107 void setDestCRS( const QgsCoordinateReferenceSystem& theCRS ); 00108 00113 const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; } 00114 00119 const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; } 00120 00128 QgsPoint transform( const QgsPoint p, TransformDirection direction = ForwardTransform ) const; 00129 00138 QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const; 00139 00150 QgsRectangle transformBoundingBox( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const; 00151 00152 // Same as for the other transform() functions, but alters the x 00153 // and y variables in place. The second one works with good old-fashioned 00154 // C style arrays. 00155 void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const; 00156 00157 void transformInPlace( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z, 00158 TransformDirection direction = ForwardTransform ) const; 00159 00160 #ifdef ANDROID 00161 void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const; 00162 00163 void transformInPlace( std::vector<float>& x, std::vector<float>& y, std::vector<float>& z, 00164 TransformDirection direction = ForwardTransform ) const; 00165 #endif 00166 00174 QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const; 00175 00186 void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const; 00187 00192 bool isInitialised() const {return mInitialisedFlag;}; 00193 00197 bool isShortCircuited() {return mShortCircuit;}; 00198 00208 void setDestCRSID( long theCRSID ); 00209 00210 public slots: 00212 void initialise(); 00213 00218 bool readXML( QDomNode & theNode ); 00219 00225 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00226 00227 signals: 00229 void invalidTransformInput() const; 00230 00231 private: 00232 00237 bool mShortCircuit; 00238 00242 bool mInitialisedFlag; 00243 00247 QgsCoordinateReferenceSystem mSourceCRS; 00248 00252 QgsCoordinateReferenceSystem mDestCRS; 00253 00257 projPJ mSourceProjection; 00258 00262 projPJ mDestinationProjection; 00263 00267 void setFinder(); 00268 }; 00269 00271 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r ) 00272 { 00273 QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ); 00274 mySummary += "\n\tInitialised? : "; 00275 //prevent warnings 00276 if ( r.isInitialised() ) 00277 { 00278 //do nothing this is a dummy 00279 } 00280 00281 #if 0 00282 if ( r.isInitialised() ) 00283 { 00284 mySummary += "Yes"; 00285 } 00286 else 00287 { 00288 mySummary += "No" ; 00289 } 00290 mySummary += "\n\tShort Circuit? : " ; 00291 if ( r.isShortCircuited() ) 00292 { 00293 mySummary += "Yes"; 00294 } 00295 else 00296 { 00297 mySummary += "No" ; 00298 } 00299 00300 mySummary += "\n\tSource Spatial Ref Sys : "; 00301 if ( r.sourceCrs() ) 00302 { 00303 mySummary << r.sourceCrs(); 00304 } 00305 else 00306 { 00307 mySummary += "Undefined" ; 00308 } 00309 00310 mySummary += "\n\tDest Spatial Ref Sys : " ; 00311 if ( r.destCRS() ) 00312 { 00313 mySummary << r.destCRS(); 00314 } 00315 else 00316 { 00317 mySummary += "Undefined" ; 00318 } 00319 #endif 00320 00321 mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" ); 00322 return os << mySummary.toLocal8Bit().data() << std::endl; 00323 } 00324 00325 00326 #endif // QGSCOORDINATETRANSFORM_H