Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgsdistancearea.h - Distance and area calculations on the ellipsoid 00003 --------------------------------------------------------------------------- 00004 Date : September 2005 00005 Copyright : (C) 2005 by Martin Dobias 00006 email : won.der at centrum.sk 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #ifndef QGSDISTANCEAREA_H 00017 #define QGSDISTANCEAREA_H 00018 00019 #include <QList> 00020 #include "qgscoordinatetransform.h" 00021 00022 class QgsGeometry; 00023 00034 class CORE_EXPORT QgsDistanceArea 00035 { 00036 public: 00038 QgsDistanceArea(); 00039 00041 ~QgsDistanceArea(); 00042 00044 void setProjectionsEnabled( bool flag ); 00045 00047 bool hasCrsTransformEnabled() { return mProjectionsEnabled; } 00048 00050 void setSourceCrs( long srsid ); 00051 00053 Q_DECL_DEPRECATED void setSourceEpsgCrsId( long epsgId ); 00054 00056 void setSourceAuthId( QString authid ); 00057 00059 long sourceCrs() { return mSourceRefSys; } 00061 bool geographic() { return mCoordTransform->sourceCrs().geographicFlag(); } 00062 00064 bool setEllipsoid( const QString& ellipsoid ); 00065 00067 const QString& ellipsoid() { return mEllipsoid; } 00068 00070 double ellipsoidSemiMajor() { return mSemiMajor; } 00072 double ellipsoidSemiMinor() { return mSemiMinor; } 00074 double ellipsoidInverseFlattening() { return mInvFlattening; } 00075 00077 double measure( QgsGeometry* geometry ); 00078 00080 double measurePerimeter( QgsGeometry* geometry ); 00081 00083 double measureLine( const QList<QgsPoint>& points ); 00084 00086 double measureLine( const QgsPoint& p1, const QgsPoint& p2 ); 00087 00089 double measurePolygon( const QList<QgsPoint>& points ); 00090 00092 double bearing( const QgsPoint& p1, const QgsPoint& p2 ); 00093 00094 static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false ); 00095 00096 protected: 00098 unsigned char* measureLine( unsigned char* feature, double* area, bool hasZptr = false ); 00100 unsigned char* measurePolygon( unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ); 00101 00112 double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2, 00113 double* course1 = NULL, double* course2 = NULL ); 00114 00115 00121 double computePolygonArea( const QList<QgsPoint>& points ); 00122 00123 double computePolygonFlatArea( const QList<QgsPoint>& points ); 00124 00129 void computeAreaInit(); 00130 00131 private: 00132 00134 QgsCoordinateTransform* mCoordTransform; 00135 00137 bool mProjectionsEnabled; 00138 00140 long mSourceRefSys; 00141 00143 QString mEllipsoid; 00144 00146 double mSemiMajor, mSemiMinor, mInvFlattening; 00147 00148 // utility functions for polygon area measurement 00149 00150 double getQ( double x ); 00151 double getQbar( double x ); 00152 00153 // temporary area measurement stuff 00154 00155 double m_QA, m_QB, m_QC; 00156 double m_QbarA, m_QbarB, m_QbarC, m_QbarD; 00157 double m_AE; /* a^2(1-e^2) */ 00158 double m_Qp; /* Q at the north pole */ 00159 double m_E; /* area of the earth */ 00160 double m_TwoPI; 00161 00162 }; 00163 00164 #endif