QGIS API Documentation  2.13.0-Master
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsDistanceArea Class Reference

General purpose distance and area calculator. More...

#include <qgsdistancearea.h>

Public Member Functions

 QgsDistanceArea ()
 Constructor. More...
 
 QgsDistanceArea (const QgsDistanceArea &origDA)
 Copy constructor. More...
 
 ~QgsDistanceArea ()
 Destructor. More...
 
double bearing (const QgsPoint &p1, const QgsPoint &p2) const
 compute bearing - in radians More...
 
double convertLengthMeasurement (double length, QGis::UnitType toUnits) const
 Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different distance unit. More...
 
void convertMeasurement (double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea) const
 Helper for conversion between physical units. More...
 
QString ellipsoid () const
 Returns ellipsoid's acronym. More...
 
bool ellipsoidalEnabled () const
 Returns whether ellipsoidal calculations are enabled. More...
 
double ellipsoidInverseFlattening () const
 returns ellipsoid's inverse flattening More...
 
double ellipsoidSemiMajor () const
 returns ellipsoid's semi major axis More...
 
double ellipsoidSemiMinor () const
 returns ellipsoid's semi minor axis More...
 
bool geographic () const
 What sort of coordinate system is being used? More...
 
QGis::UnitType lengthUnits () const
 Returns the units of distance for length calculations made by this object. More...
 
Q_DECL_DEPRECATED double measure (const QgsGeometry *geometry) const
 General measurement (line distance or polygon area) More...
 
double measureArea (const QgsGeometry *geometry) const
 Measures the area of a geometry. More...
 
double measureLength (const QgsGeometry *geometry) const
 Measures the length of a geometry. More...
 
double measureLine (const QList< QgsPoint > &points) const
 Measures the length of a line with multiple segments. More...
 
double measureLine (const QgsPoint &p1, const QgsPoint &p2) const
 Measures length of a line with one segment. More...
 
double measureLine (const QgsPoint &p1, const QgsPoint &p2, QGis::UnitType &units) const
 Measures length of line with one segment and returns units of distance. More...
 
double measurePerimeter (const QgsGeometry *geometry) const
 Measures the perimeter of a polygon geometry. More...
 
double measurePolygon (const QList< QgsPoint > &points) const
 measures polygon area More...
 
QgsDistanceAreaoperator= (const QgsDistanceArea &origDA)
 Assignment operator. More...
 
bool setEllipsoid (const QString &ellipsoid)
 Sets ellipsoid by its acronym. More...
 
bool setEllipsoid (double semiMajor, double semiMinor)
 Sets ellipsoid by supplied radii. More...
 
void setEllipsoidalMode (bool flag)
 Sets whether coordinates must be projected to ellipsoid before measuring. More...
 
void setSourceAuthId (const QString &authid)
 sets source spatial reference system by authid 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...
 
Q_DECL_DEPRECATED long sourceCrs () const
 returns source spatial reference system More...
 
long sourceCrsId () const
 Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations. More...
 
bool willUseEllipsoid () const
 Returns whether calculations will use the ellipsoid. More...
 

Static Public Member Functions

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

Protected Member Functions

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

Detailed Description

General purpose distance and area calculator.

Definition at line 37 of file qgsdistancearea.h.

Constructor & Destructor Documentation

QgsDistanceArea::QgsDistanceArea ( )

Constructor.

Definition at line 48 of file qgsdistancearea.cpp.

QgsDistanceArea::~QgsDistanceArea ( )

Destructor.

Definition at line 65 of file qgsdistancearea.cpp.

QgsDistanceArea::QgsDistanceArea ( const QgsDistanceArea origDA)

Copy constructor.

Definition at line 59 of file qgsdistancearea.cpp.

Member Function Documentation

double QgsDistanceArea::bearing ( const QgsPoint p1,
const QgsPoint p2 
) const

compute bearing - in radians

Definition at line 678 of file qgsdistancearea.cpp.

void QgsDistanceArea::computeAreaInit ( )
protected

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

Definition at line 851 of file qgsdistancearea.cpp.

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

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

Definition at line 785 of file qgsdistancearea.cpp.

double QgsDistanceArea::computeDistanceBearing ( const QgsPoint p1,
const QgsPoint p2,
double *  course1 = nullptr,
double *  course2 = nullptr 
) const
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 703 of file qgsdistancearea.cpp.

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

uses flat / planimetric / Euclidean distance

Definition at line 780 of file qgsdistancearea.cpp.

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

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

Definition at line 886 of file qgsdistancearea.cpp.

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

Definition at line 943 of file qgsdistancearea.cpp.

double QgsDistanceArea::convertLengthMeasurement ( double  length,
QGis::UnitType  toUnits 
) const

Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different distance unit.

Parameters
lengthlength value calculated by this class to convert. It is assumed that the length was calculated by this class, ie that its unit of length is equal lengthUnits().
toUnitsdistance unit to convert measurement to
Returns
converted distance

Definition at line 1125 of file qgsdistancearea.cpp.

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

Helper for conversion between physical units.

Definition at line 1094 of file qgsdistancearea.cpp.

QString QgsDistanceArea::ellipsoid ( ) const
inline

Returns ellipsoid's acronym.

Calculations will only use the ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.

See also
setEllipsoid()
ellipsoidalEnabled()
willUseEllipsoid()

Definition at line 125 of file qgsdistancearea.h.

bool QgsDistanceArea::ellipsoidalEnabled ( ) const
inline

Returns whether ellipsoidal calculations are enabled.

See also
willUseEllipsoid()
setEllipsoidalMode()

Definition at line 64 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidInverseFlattening ( ) const
inline

returns ellipsoid's inverse flattening

Definition at line 132 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidSemiMajor ( ) const
inline

returns ellipsoid's semi major axis

Definition at line 128 of file qgsdistancearea.h.

double QgsDistanceArea::ellipsoidSemiMinor ( ) const
inline

returns ellipsoid's semi minor axis

Definition at line 130 of file qgsdistancearea.h.

bool QgsDistanceArea::geographic ( ) const
inline

What sort of coordinate system is being used?

Definition at line 98 of file qgsdistancearea.h.

QGis::UnitType QgsDistanceArea::lengthUnits ( ) const

Returns the units of distance for length calculations made by this object.

Note
added in QGIS 2.14

Definition at line 537 of file qgsdistancearea.cpp.

double QgsDistanceArea::measure ( const QgsGeometry geometry) const

General measurement (line distance or polygon area)

Deprecated:
use measureArea() or measureLength() methods instead, as this method is unpredictable for geometry collections

Definition at line 353 of file qgsdistancearea.cpp.

double QgsDistanceArea::measureArea ( const QgsGeometry geometry) const

Measures the area of a geometry.

Parameters
geometrygeometry to measure
Returns
area of geometry. For geometry collections, non surface geometries will be ignored
Note
added in QGIS 2.12
See also
measureLength()
measurePerimeter()

Definition at line 362 of file qgsdistancearea.cpp.

double QgsDistanceArea::measureLength ( const QgsGeometry geometry) const

Measures the length of a geometry.

Parameters
geometrygeometry to measure
Returns
length of geometry. For geometry collections, non curve geometries will be ignored. The units for the returned distance can be retrieved by calling lengthUnits().
Note
added in QGIS 2.12
See also
lengthUnits()
measureArea()
measurePerimeter()

Definition at line 371 of file qgsdistancearea.cpp.

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

Measures the length of a line with multiple segments.

Parameters
pointslist of points in line
Returns
length of line. The units for the returned length can be retrieved by calling lengthUnits().
See also
lengthUnits()

Definition at line 452 of file qgsdistancearea.cpp.

double QgsDistanceArea::measureLine ( const QgsPoint p1,
const QgsPoint p2 
) const

Measures length of a line with one segment.

Parameters
p1start of line
p2end of line
Returns
distance between points. The units for the returned distance can be retrieved by calling lengthUnits().
See also
lengthUnits()

Definition at line 494 of file qgsdistancearea.cpp.

double QgsDistanceArea::measureLine ( const QgsPoint p1,
const QgsPoint p2,
QGis::UnitType units 
) const

Measures length of line with one segment and returns units of distance.

Parameters
p1start of line
p2end of line
unitswill be set to units of measure
Returns
calculated distance between points. Distance units are stored in units parameter.
Note
added in QGIS 2.12

Definition at line 500 of file qgsdistancearea.cpp.

double QgsDistanceArea::measurePerimeter ( const QgsGeometry geometry) const

Measures the perimeter of a polygon geometry.

Parameters
geometrygeometry to measure
Returns
perimeter of geometry. For geometry collections, any non-polygon geometries will be ignored. The units for the returned perimeter can be retrieved by calling lengthUnits().
Note
added in QGIS 2.12
See also
lengthUnits()
measureArea()
measurePerimeter()

Definition at line 380 of file qgsdistancearea.cpp.

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

measures polygon area

Definition at line 651 of file qgsdistancearea.cpp.

QgsConstWkbPtr QgsDistanceArea::measurePolygon ( QgsConstWkbPtr  feature,
double *  area,
double *  perimeter,
bool  hasZptr = false 
) const
protected

measures polygon area and perimeter, vertices are extracted from WKB

Definition at line 542 of file qgsdistancearea.cpp.

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

Assignment operator.

Definition at line 71 of file qgsdistancearea.cpp.

bool QgsDistanceArea::setEllipsoid ( const QString ellipsoid)

Sets ellipsoid by its acronym.

Calculations will only use the ellipsoid if both the ellipsoid has been set and ellipsoidalEnabled() is true.

Returns
true if ellipsoid was successfully set
See also
ellipsoid()
setEllipsoidalMode()
willUseEllipsoid()

Definition at line 126 of file qgsdistancearea.cpp.

bool QgsDistanceArea::setEllipsoid ( double  semiMajor,
double  semiMinor 
)

Sets ellipsoid by supplied radii.

Calculations will only use the ellipsoid if both the ellipsoid has been set and ellipsoidalEnabled() is true.

Returns
true if ellipsoid was successfully set
See also
ellipsoid()
setEllipsoidalMode()
willUseEllipsoid()

Definition at line 260 of file qgsdistancearea.cpp.

void QgsDistanceArea::setEllipsoidalMode ( bool  flag)

Sets whether coordinates must be projected to ellipsoid before measuring.

Note
for calculations to use the ellipsoid, both the ellipsoid mode must be true and an ellipse must be set
See also
setEllipsoid()
willUseEllipsoid()

Definition at line 97 of file qgsdistancearea.cpp.

void QgsDistanceArea::setSourceAuthId ( const QString authid)

sets source spatial reference system by authid

Definition at line 119 of file qgsdistancearea.cpp.

void QgsDistanceArea::setSourceCrs ( long  srsid)

sets source spatial reference system (by QGIS CRS)

Definition at line 107 of file qgsdistancearea.cpp.

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 114 of file qgsdistancearea.cpp.

Q_DECL_DEPRECATED long QgsDistanceArea::sourceCrs ( ) const
inline

returns source spatial reference system

Deprecated:
use sourceCrsId() instead

Definition at line 89 of file qgsdistancearea.h.

long QgsDistanceArea::sourceCrsId ( ) const
inline

Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations.

See also
setSourceCrs()
Note
added in QGIS 2.14

Definition at line 95 of file qgsdistancearea.h.

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

Definition at line 964 of file qgsdistancearea.cpp.

bool QgsDistanceArea::willUseEllipsoid ( ) const

Returns whether calculations will use the ellipsoid.

Calculations will only use the ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.

Note
added in QGIS 2.14
See also
ellipsoidalEnabled()
ellipsoid()

Definition at line 102 of file qgsdistancearea.cpp.


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