|
QGIS API Documentation
master-3f58142
|
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 class QPolygonF; 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 00159 void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z, 00160 TransformDirection direction = ForwardTransform ) const; 00161 00162 void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const; 00163 00164 #ifdef ANDROID 00165 void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const; 00166 00167 void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z, 00168 TransformDirection direction = ForwardTransform ) const; 00169 #endif 00170 00178 QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const; 00179 00190 void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const; 00191 00196 bool isInitialised() const {return mInitialisedFlag;}; 00197 00201 bool isShortCircuited() {return mShortCircuit;}; 00202 00212 void setDestCRSID( long theCRSID ); 00213 00214 public slots: 00216 void initialise(); 00217 00222 bool readXML( QDomNode & theNode ); 00223 00229 bool writeXML( QDomNode & theNode, QDomDocument & theDoc ); 00230 00231 signals: 00233 void invalidTransformInput() const; 00234 00235 private: 00236 00241 bool mShortCircuit; 00242 00246 bool mInitialisedFlag; 00247 00251 QgsCoordinateReferenceSystem mSourceCRS; 00252 00256 QgsCoordinateReferenceSystem mDestCRS; 00257 00261 projPJ mSourceProjection; 00262 00266 projPJ mDestinationProjection; 00267 00271 void setFinder(); 00272 }; 00273 00275 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r ) 00276 { 00277 QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ); 00278 mySummary += "\n\tInitialised? : "; 00279 //prevent warnings 00280 if ( r.isInitialised() ) 00281 { 00282 //do nothing this is a dummy 00283 } 00284 00285 #if 0 00286 if ( r.isInitialised() ) 00287 { 00288 mySummary += "Yes"; 00289 } 00290 else 00291 { 00292 mySummary += "No" ; 00293 } 00294 mySummary += "\n\tShort Circuit? : " ; 00295 if ( r.isShortCircuited() ) 00296 { 00297 mySummary += "Yes"; 00298 } 00299 else 00300 { 00301 mySummary += "No" ; 00302 } 00303 00304 mySummary += "\n\tSource Spatial Ref Sys : "; 00305 if ( r.sourceCrs() ) 00306 { 00307 mySummary << r.sourceCrs(); 00308 } 00309 else 00310 { 00311 mySummary += "Undefined" ; 00312 } 00313 00314 mySummary += "\n\tDest Spatial Ref Sys : " ; 00315 if ( r.destCRS() ) 00316 { 00317 mySummary << r.destCRS(); 00318 } 00319 else 00320 { 00321 mySummary += "Undefined" ; 00322 } 00323 #endif 00324 00325 mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" ); 00326 return os << mySummary.toLocal8Bit().data() << std::endl; 00327 } 00328 00329 00330 #endif // QGSCOORDINATETRANSFORM_H