QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
QgsDistanceArea Class Reference

General purpose distance and area calculator. More...

#include <qgsdistancearea.h>

Collaboration diagram for QgsDistanceArea:
Collaboration graph
[legend]

Public Member Functions

 QgsDistanceArea ()
 Constructor. More...
 
 ~QgsDistanceArea ()
 Destructor. More...
 
 QgsDistanceArea (const QgsDistanceArea &origDA)
 Copy constructor. More...
 
QgsDistanceAreaoperator= (const QgsDistanceArea &origDA)
 Assignment operator. More...
 
void setEllipsoidalMode (bool flag)
 sets whether coordinates must be projected to ellipsoid before measuring More...
 
bool ellipsoidalEnabled () const
 returns projections enabled flag More...
 
void setSourceCrs (long srsid)
 sets source spatial reference system (by QGIS CRS) More...
 
void setSourceCrs (const QgsCoordinateReferenceSystem &srcCRS)
 Sets source spatial reference system (by QGIS CRS) More...
 
void setSourceAuthId (QString authid)
 sets source spatial reference system by authid More...
 
long sourceCrs () const
 returns source spatial reference system More...
 
bool geographic () const
 What sort of coordinate system is being used? More...
 
bool setEllipsoid (const QString &ellipsoid)
 sets ellipsoid by its acronym More...
 
bool setEllipsoid (double semiMajor, double semiMinor)
 Sets ellipsoid by supplied radii. More...
 
const QString & ellipsoid () const
 returns ellipsoid's acronym More...
 
double ellipsoidSemiMajor () const
 returns ellipsoid's semi major axis More...
 
double ellipsoidSemiMinor () const
 returns ellipsoid's semi minor axis More...
 
double ellipsoidInverseFlattening () const
 returns ellipsoid's inverse flattening More...
 
double measure (QgsGeometry *geometry)
 general measurement (line distance or polygon area) More...
 
double measurePerimeter (QgsGeometry *geometry)
 measures perimeter of polygon More...
 
double measureLine (const QList< QgsPoint > &points)
 measures line More...
 
double measureLine (const QgsPoint &p1, const QgsPoint &p2)
 measures line with one segment More...
 
double measurePolygon (const QList< QgsPoint > &points)
 measures polygon area More...
 
double bearing (const QgsPoint &p1, const QgsPoint &p2)
 compute bearing - in radians More...
 
void convertMeasurement (double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea)
 Helper for conversion between physical units. More...
 

Static Public Member Functions

static QString textUnit (double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit=false)
 

Protected Member Functions

const unsigned char * measureLine (const unsigned char *feature, double *area, bool hasZptr=false)
 measures line distance, line points are extracted from WKB More...
 
const unsigned char * measurePolygon (const unsigned char *feature, double *area, double *perimeter, bool hasZptr=false)
 measures polygon area and perimeter, vertices are extracted from WKB More...
 
double computeDistanceBearing (const QgsPoint &p1, const QgsPoint &p2, double *course1=NULL, double *course2=NULL)
 calculates distance from two points on ellipsoid based on inverse Vincenty's formulae More...
 
double computeDistanceFlat (const QgsPoint &p1, const QgsPoint &p2)
 uses flat / planimetric / Euclidean distance More...
 
double computeDistance (const QList< QgsPoint > &points)
 calculate distance with given coordinates (does not do a transform anymore) More...
 
double computePolygonArea (const QList< QgsPoint > &points)
 calculates area of polygon on ellipsoid algorithm has been taken from GRASS: gis/area_poly1.c More...
 
double computePolygonFlatArea (const QList< QgsPoint > &points)
 
void computeAreaInit ()
 precalculates some values (must be called always when changing ellipsoid) More...
 

Private Member Functions

void _copy (const QgsDistanceArea &origDA)
 Copy helper. More...
 
double getQ (double x)
 
double getQbar (double x)
 

Private Attributes

QgsCoordinateTransformmCoordTransform
 used for transforming coordinates from source CRS to ellipsoid's coordinates More...
 
bool mEllipsoidalMode
 indicates whether we will transform coordinates More...
 
QString mEllipsoid
 ellipsoid acronym (from table tbl_ellipsoids) More...
 
double mSemiMajor
 ellipsoid parameters More...
 
double mSemiMinor
 
double mInvFlattening
 
double m_QA
 
double m_QB
 
double m_QC
 
double m_QbarA
 
double m_QbarB
 
double m_QbarC
 
double m_QbarD
 
double m_AE
 
double m_Qp
 
double m_E
 
double m_TwoPI
 

Detailed Description

General purpose distance and area calculator.

Definition at line 34 of file qgsdistancearea.h.

Constructor & Destructor Documentation

QgsDistanceArea::QgsDistanceArea ( )

Constructor.

Definition at line 41 of file qgsdistancearea.cpp.

References GEO_NONE, GEOCRS_ID, mCoordTransform, mEllipsoidalMode, setEllipsoid(), and setSourceCrs().

QgsDistanceArea::~QgsDistanceArea ( )

Destructor.

Definition at line 57 of file qgsdistancearea.cpp.

References mCoordTransform.

QgsDistanceArea::QgsDistanceArea ( const QgsDistanceArea origDA)

Copy constructor.

Definition at line 52 of file qgsdistancearea.cpp.

References _copy().

Member Function Documentation

void QgsDistanceArea::_copy ( const QgsDistanceArea origDA)
private
double QgsDistanceArea::bearing ( const QgsPoint p1,
const QgsPoint p2 
)
void QgsDistanceArea::computeAreaInit ( )
protected

precalculates some values (must be called always when changing ellipsoid)

Definition at line 786 of file qgsdistancearea.cpp.

References getQ(), m_AE, m_E, M_PI, m_QA, m_QB, m_QbarA, m_QbarB, m_QbarC, m_QbarD, m_QC, m_Qp, m_TwoPI, mSemiMajor, and mSemiMinor.

Referenced by _copy(), and setEllipsoid().

double QgsDistanceArea::computeDistance ( const QList< QgsPoint > &  points)
protected

calculate distance with given coordinates (does not do a transform anymore)

Definition at line 720 of file qgsdistancearea.cpp.

References computeDistanceBearing(), computeDistanceFlat(), GEO_NONE, QgsMessageLog::logMessage(), mEllipsoid, mEllipsoidalMode, and tr.

Referenced by measurePolygon().

double QgsDistanceArea::computeDistanceBearing ( const QgsPoint p1,
const QgsPoint p2,
double *  course1 = NULL,
double *  course2 = NULL 
)
protected

calculates distance from two points on ellipsoid based on inverse Vincenty's formulae

Points p1 and p2 are expected to be in degrees and in currently used ellipsoid

Note
if course1 is not NULL, bearing (in radians) from first point is calculated (the same for course2)
Returns
distance in meters

Definition at line 638 of file qgsdistancearea.cpp.

References DEG2RAD, M_PI, mInvFlattening, mSemiMajor, mSemiMinor, QgsPoint::x(), and QgsPoint::y().

Referenced by bearing(), computeDistance(), and measureLine().

double QgsDistanceArea::computeDistanceFlat ( const QgsPoint p1,
const QgsPoint p2 
)
protected

uses flat / planimetric / Euclidean distance

Definition at line 715 of file qgsdistancearea.cpp.

References QgsPoint::x(), and QgsPoint::y().

Referenced by computeDistance(), and measureLine().

double QgsDistanceArea::computePolygonArea ( const QList< QgsPoint > &  points)
protected

calculates area of polygon on ellipsoid algorithm has been taken from GRASS: gis/area_poly1.c

Definition at line 815 of file qgsdistancearea.cpp.

References computePolygonFlatArea(), DEG2RAD, GEO_NONE, getQ(), getQbar(), m_AE, m_E, M_PI, m_Qp, m_TwoPI, mEllipsoid, mEllipsoidalMode, and QgsDebugMsgLevel.

Referenced by measurePolygon().

double QgsDistanceArea::computePolygonFlatArea ( const QList< QgsPoint > &  points)
protected

Definition at line 872 of file qgsdistancearea.cpp.

References size.

Referenced by computePolygonArea().

void QgsDistanceArea::convertMeasurement ( double &  measure,
QGis::UnitType measureUnits,
QGis::UnitType  displayUnits,
bool  isArea 
)
const QString& QgsDistanceArea::ellipsoid ( ) const
inline

returns ellipsoid's acronym

Definition at line 80 of file qgsdistancearea.h.

Referenced by setEllipsoid().

bool QgsDistanceArea::ellipsoidalEnabled ( ) const
inline

returns projections enabled flag

Definition at line 53 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidInverseFlattening ( ) const
inline

returns ellipsoid's inverse flattening

Definition at line 87 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidSemiMajor ( ) const
inline

returns ellipsoid's semi major axis

Definition at line 83 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidSemiMinor ( ) const
inline

returns ellipsoid's semi minor axis

Definition at line 85 of file qgsdistancearea.h.

bool QgsDistanceArea::geographic ( ) const
inline

What sort of coordinate system is being used?

Definition at line 70 of file qgsdistancearea.h.

double QgsDistanceArea::getQ ( double  x)
private

Definition at line 764 of file qgsdistancearea.cpp.

References m_QA, m_QB, and m_QC.

Referenced by computeAreaInit(), and computePolygonArea().

double QgsDistanceArea::getQbar ( double  x)
private

Definition at line 775 of file qgsdistancearea.cpp.

References m_QbarA, m_QbarB, m_QbarC, and m_QbarD.

Referenced by computePolygonArea().

double QgsDistanceArea::measure ( QgsGeometry geometry)
double QgsDistanceArea::measureLine ( const QList< QgsPoint > &  points)
double QgsDistanceArea::measureLine ( const QgsPoint p1,
const QgsPoint p2 
)
const unsigned char * QgsDistanceArea::measureLine ( const unsigned char *  feature,
double *  area,
bool  hasZptr = false 
)
protected

measures line distance, line points are extracted from WKB

Definition at line 386 of file qgsdistancearea.cpp.

References measureLine(), and QgsDebugMsg.

double QgsDistanceArea::measurePerimeter ( QgsGeometry geometry)
double QgsDistanceArea::measurePolygon ( const QList< QgsPoint > &  points)
const unsigned char * QgsDistanceArea::measurePolygon ( const unsigned char *  feature,
double *  area,
double *  perimeter,
bool  hasZptr = false 
)
protected

measures polygon area and perimeter, vertices are extracted from WKB

Definition at line 491 of file qgsdistancearea.cpp.

References computeDistance(), computePolygonArea(), GEO_NONE, QgsMessageLog::logMessage(), mCoordTransform, mEllipsoid, mEllipsoidalMode, QgsDebugMsg, tr, and QgsCoordinateTransform::transform().

QgsDistanceArea & QgsDistanceArea::operator= ( const QgsDistanceArea origDA)

Assignment operator.

Definition at line 63 of file qgsdistancearea.cpp.

References _copy().

bool QgsDistanceArea::setEllipsoid ( const QString &  ellipsoid)
bool QgsDistanceArea::setEllipsoid ( double  semiMajor,
double  semiMinor 
)

Sets ellipsoid by supplied radii.

Definition at line 245 of file qgsdistancearea.cpp.

References computeAreaInit(), mEllipsoid, mInvFlattening, mSemiMajor, and mSemiMinor.

void QgsDistanceArea::setEllipsoidalMode ( bool  flag)
void QgsDistanceArea::setSourceAuthId ( QString  authid)

sets source spatial reference system by authid

Definition at line 105 of file qgsdistancearea.cpp.

References QgsCoordinateReferenceSystem::createFromOgcWmsCrs(), mCoordTransform, and QgsCoordinateTransform::setSourceCrs().

void QgsDistanceArea::setSourceCrs ( long  srsid)
void QgsDistanceArea::setSourceCrs ( const QgsCoordinateReferenceSystem srcCRS)

Sets source spatial reference system (by QGIS CRS)

Note
: missing in Python bindings in QGIS < 2.2

Definition at line 100 of file qgsdistancearea.cpp.

References mCoordTransform, and QgsCoordinateTransform::setSourceCrs().

long QgsDistanceArea::sourceCrs ( ) const
inline

returns source spatial reference system

Definition at line 68 of file qgsdistancearea.h.

QString QgsDistanceArea::textUnit ( double  value,
int  decimals,
QGis::UnitType  u,
bool  isArea,
bool  keepBaseUnit = false 
)
static

Member Data Documentation

double QgsDistanceArea::m_AE
private

Definition at line 179 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and computePolygonArea().

double QgsDistanceArea::m_E
private

Definition at line 181 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and computePolygonArea().

double QgsDistanceArea::m_QA
private

Definition at line 177 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQ().

double QgsDistanceArea::m_QB
private

Definition at line 177 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQ().

double QgsDistanceArea::m_QbarA
private

Definition at line 178 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQbar().

double QgsDistanceArea::m_QbarB
private

Definition at line 178 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQbar().

double QgsDistanceArea::m_QbarC
private

Definition at line 178 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQbar().

double QgsDistanceArea::m_QbarD
private

Definition at line 178 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQbar().

double QgsDistanceArea::m_QC
private

Definition at line 177 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and getQ().

double QgsDistanceArea::m_Qp
private

Definition at line 180 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and computePolygonArea().

double QgsDistanceArea::m_TwoPI
private

Definition at line 182 of file qgsdistancearea.h.

Referenced by computeAreaInit(), and computePolygonArea().

QgsCoordinateTransform* QgsDistanceArea::mCoordTransform
private

used for transforming coordinates from source CRS to ellipsoid's coordinates

Definition at line 159 of file qgsdistancearea.h.

Referenced by _copy(), bearing(), convertMeasurement(), measureLine(), measurePolygon(), QgsDistanceArea(), setEllipsoid(), setSourceAuthId(), setSourceCrs(), and ~QgsDistanceArea().

QString QgsDistanceArea::mEllipsoid
private

ellipsoid acronym (from table tbl_ellipsoids)

Definition at line 165 of file qgsdistancearea.h.

Referenced by _copy(), bearing(), computeDistance(), computePolygonArea(), convertMeasurement(), measureLine(), measurePolygon(), and setEllipsoid().

bool QgsDistanceArea::mEllipsoidalMode
private

indicates whether we will transform coordinates

Definition at line 162 of file qgsdistancearea.h.

Referenced by _copy(), bearing(), computeDistance(), computePolygonArea(), convertMeasurement(), measureLine(), measurePolygon(), QgsDistanceArea(), and setEllipsoidalMode().

double QgsDistanceArea::mInvFlattening
private

Definition at line 168 of file qgsdistancearea.h.

Referenced by _copy(), computeDistanceBearing(), and setEllipsoid().

double QgsDistanceArea::mSemiMajor
private

ellipsoid parameters

Definition at line 168 of file qgsdistancearea.h.

Referenced by _copy(), computeAreaInit(), computeDistanceBearing(), and setEllipsoid().

double QgsDistanceArea::mSemiMinor
private

Definition at line 168 of file qgsdistancearea.h.

Referenced by _copy(), computeAreaInit(), computeDistanceBearing(), and setEllipsoid().


The documentation for this class was generated from the following files: