Quantum GIS API Documentation  1.7.4
src/core/qgsdistancearea.h
Go to the documentation of this file.
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 /* $Id$ */
00016 
00017 #ifndef QGSDISTANCEAREA_H
00018 #define QGSDISTANCEAREA_H
00019 
00020 #include <QList>
00021 #include "qgscoordinatetransform.h"
00022 
00023 class QgsGeometry;
00024 
00035 class CORE_EXPORT QgsDistanceArea
00036 {
00037   public:
00039     QgsDistanceArea();
00040 
00042     ~QgsDistanceArea();
00043 
00045     void setProjectionsEnabled( bool flag );
00046 
00048     bool hasCrsTransformEnabled() { return mProjectionsEnabled; }
00049 
00051     void setSourceCrs( long srsid );
00052 
00054     Q_DECL_DEPRECATED void setSourceEpsgCrsId( long epsgId );
00055 
00057     void setSourceAuthId( QString authid );
00058 
00060     long sourceCrs() { return mSourceRefSys; }
00062     bool geographic() { return mCoordTransform->sourceCrs().geographicFlag(); }
00063 
00065     bool setEllipsoid( const QString& ellipsoid );
00066 
00068     const QString& ellipsoid() { return mEllipsoid; }
00069 
00071     double ellipsoidSemiMajor() { return mSemiMajor; }
00073     double ellipsoidSemiMinor() { return mSemiMinor; }
00075     double ellipsoidInverseFlattening() { return mInvFlattening; }
00076 
00078     double measure( QgsGeometry* geometry );
00079 
00081     double measurePerimeter( QgsGeometry* geometry );
00082 
00084     double measureLine( const QList<QgsPoint>& points );
00085 
00087     double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
00088 
00090     double measurePolygon( const QList<QgsPoint>& points );
00091 
00093     double bearing( const QgsPoint& p1, const QgsPoint& p2 );
00094 
00095     static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
00096 
00097   protected:
00099     unsigned char* measureLine( unsigned char* feature, double* area, bool hasZptr = false );
00101     unsigned char* measurePolygon( unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
00102 
00113     double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
00114                                    double* course1 = NULL, double* course2 = NULL );
00115 
00116 
00122     double computePolygonArea( const QList<QgsPoint>& points );
00123 
00124     double computePolygonFlatArea( const QList<QgsPoint>& points );
00125 
00130     void computeAreaInit();
00131 
00132   private:
00133 
00135     QgsCoordinateTransform* mCoordTransform;
00136 
00138     bool mProjectionsEnabled;
00139 
00141     long mSourceRefSys;
00142 
00144     QString mEllipsoid;
00145 
00147     double mSemiMajor, mSemiMinor, mInvFlattening;
00148 
00149     // utility functions for polygon area measurement
00150 
00151     double getQ( double x );
00152     double getQbar( double x );
00153 
00154     // temporary area measurement stuff
00155 
00156     double m_QA, m_QB, m_QC;
00157     double m_QbarA, m_QbarB, m_QbarC, m_QbarD;
00158     double m_AE;  /* a^2(1-e^2) */
00159     double m_Qp;  /* Q at the north pole */
00160     double m_E;   /* area of the earth */
00161     double m_TwoPI;
00162 
00163 };
00164 
00165 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines