QGIS API Documentation  2.99.0-Master (13a3f2f)
Public Member Functions | Static Public Member Functions | List of all members
QgsDistanceArea Class Reference

A general purpose distance and area calculator, capable of performing ellipsoid based calculations. More...

#include <qgsdistancearea.h>

Public Member Functions

 QgsDistanceArea ()
 Constructor. More...
 
QgsUnitTypes::AreaUnit areaUnits () const
 Returns the units of area for areal calculations made by this object. More...
 
double bearing (const QgsPoint &p1, const QgsPoint &p2) const
 Computes the bearing (in radians) between two points. More...
 
QgsPoint computeSpheroidProject (const QgsPoint &p1, double distance=1, double azimuth=M_PI/2) const
 Given a location, an azimuth and a distance, computes the location of the projected point. More...
 
double convertAreaMeasurement (double area, QgsUnitTypes::AreaUnit toUnits) const
 Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different areal unit. More...
 
double convertLengthMeasurement (double length, QgsUnitTypes::DistanceUnit toUnits) const
 Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different distance unit. More...
 
QString ellipsoid () const
 Returns ellipsoid's acronym. More...
 
double ellipsoidInverseFlattening () const
 Returns ellipsoid's inverse flattening. More...
 
double ellipsoidSemiMajor () const
 Returns the ellipsoid's semi major axis. More...
 
double ellipsoidSemiMinor () const
 Returns ellipsoid's semi minor axis. More...
 
QgsUnitTypes::DistanceUnit lengthUnits () const
 Returns the units of distance for length calculations made by this object. 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 the distance between two points. More...
 
double measureLineProjected (const QgsPoint &p1, double distance=1, double azimuth=M_PI/2, QgsPoint *projectedPoint=nullptr) const
 Calculates the distance from one point with distance in meters and azimuth (direction) When the sourceCrs() is geographic, computeSpheroidProject() will be called otherwise QgsPoint.project() will be called after QgsUnitTypes::fromUnitToUnitFactor() has been applied to the distance. More...
 
double measurePerimeter (const QgsGeometry &geometry) const
 Measures the perimeter of a polygon geometry. More...
 
double measurePolygon (const QList< QgsPoint > &points) const
 Measures the area of the polygon described by a set of points. More...
 
bool setEllipsoid (const QString &ellipsoid)
 Sets the ellipsoid by its acronym. More...
 
bool setEllipsoid (double semiMajor, double semiMinor)
 Sets ellipsoid by supplied radii. More...
 
void setSourceCrs (const QgsCoordinateReferenceSystem &srcCRS)
 Sets source spatial reference system. More...
 
QgsCoordinateReferenceSystem sourceCrs () const
 Returns the source spatial reference system. More...
 
bool willUseEllipsoid () const
 Returns whether calculations will use the ellipsoid. More...
 

Static Public Member Functions

static QString formatArea (double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
 Returns an area formatted as a friendly string. More...
 
static QString formatDistance (double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit=false)
 Returns an distance formatted as a friendly string. More...
 

Detailed Description

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

Measurements can either be performed on existing QgsGeometry objects, or using lists of points.

If a valid ellipsoid() has been set for the QgsDistanceArea, all calculations will be performed using ellipsoidal algorithms (e.g. using Vincenty's formulas). If no ellipsoid has been set, all calculations will be performed using cartesian formulas only. The behavior can be determined by calling willUseEllipsoid().

In order to perform accurate calculations, the source coordinate reference system of all measured geometries must first be specified using setSourceCrs().

Usually, the measurements returned by QgsDistanceArea are in meters. If no valid ellipsoid is set, then the units may not be meters. The units can be retrieved by calling lengthUnits() and areaUnits().

Definition at line 49 of file qgsdistancearea.h.

Constructor & Destructor Documentation

◆ QgsDistanceArea()

QgsDistanceArea::QgsDistanceArea ( )

Constructor.

Definition at line 46 of file qgsdistancearea.cpp.

Member Function Documentation

◆ areaUnits()

QgsUnitTypes::AreaUnit QgsDistanceArea::areaUnits ( ) const

Returns the units of area for areal calculations made by this object.

Since
QGIS 2.14
See also
lengthUnits()

Definition at line 442 of file qgsdistancearea.cpp.

◆ bearing()

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

Computes the bearing (in radians) between two points.

Definition at line 490 of file qgsdistancearea.cpp.

◆ computeSpheroidProject()

QgsPoint QgsDistanceArea::computeSpheroidProject ( const QgsPoint p1,
double  distance = 1,
double  azimuth = M_PI / 2 
) const

Given a location, an azimuth and a distance, computes the location of the projected point.

Based on Vincenty's formula for the geodetic direct problem as described in "Geocentric Datum of Australia Technical Manual", Chapter 4.

Note
code (and documentation) taken from rttopo project https://git.osgeo.org/gogs/rttopo/librttopo
  • spheroid_project.spheroid_project(...)
Since
QGIS 3.0
Parameters
p1- location of first geographic (latitude/longitude) point as degrees.
distance- distance in meters.
azimuth- azimuth in radians, clockwise from North
Returns
p2 - location of projected point as longitude/latitude.

Definition at line 380 of file qgsdistancearea.cpp.

◆ convertAreaMeasurement()

double QgsDistanceArea::convertAreaMeasurement ( double  area,
QgsUnitTypes::AreaUnit  toUnits 
) const

Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different areal unit.

Parameters
areaarea value calculated by this class to convert. It is assumed that the area was calculated by this class, ie that its unit of area is equal to areaUnits().
toUnitsarea unit to convert measurement to
Returns
converted area
See also
convertLengthMeasurement()
Since
QGIS 2.14

Definition at line 778 of file qgsdistancearea.cpp.

◆ convertLengthMeasurement()

double QgsDistanceArea::convertLengthMeasurement ( double  length,
QgsUnitTypes::DistanceUnit  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 to lengthUnits().
toUnitsdistance unit to convert measurement to
Returns
converted distance
See also
convertAreaMeasurement()
Since
QGIS 2.14

Definition at line 764 of file qgsdistancearea.cpp.

◆ ellipsoid()

QString QgsDistanceArea::ellipsoid ( ) const
inline

Returns ellipsoid's acronym.

Calculations will only use the ellipsoid if a valid ellipsoid has been set.

See also
setEllipsoid()
willUseEllipsoid()

Definition at line 101 of file qgsdistancearea.h.

◆ ellipsoidInverseFlattening()

double QgsDistanceArea::ellipsoidInverseFlattening ( ) const
inline

Returns ellipsoid's inverse flattening.

The inverse flattening is calculated with invf = a/(a-b).

See also
ellipsoid()
ellipsoidSemiMajor()
ellipsoidSemiMinor()

Definition at line 126 of file qgsdistancearea.h.

◆ ellipsoidSemiMajor()

double QgsDistanceArea::ellipsoidSemiMajor ( ) const
inline

Returns the ellipsoid's semi major axis.

See also
ellipsoid()
ellipsoidSemiMinor()
ellipsoidInverseFlattening()

Definition at line 109 of file qgsdistancearea.h.

◆ ellipsoidSemiMinor()

double QgsDistanceArea::ellipsoidSemiMinor ( ) const
inline

Returns ellipsoid's semi minor axis.

See also
ellipsoid()
ellipsoidSemiMajor()
ellipsoidInverseFlattening()

Definition at line 117 of file qgsdistancearea.h.

◆ formatArea()

QString QgsDistanceArea::formatArea ( double  area,
int  decimals,
QgsUnitTypes::AreaUnit  unit,
bool  keepBaseUnit = false 
)
static

Returns an area formatted as a friendly string.

Parameters
areaarea to format
decimalsnumber of decimal places to show
unitunit of area
keepBaseUnitset to false to allow conversion of large areas to more suitable units, e.g., square meters to square kilometers
Returns
formatted area string
Since
QGIS 2.14
See also
formatDistance()

Definition at line 759 of file qgsdistancearea.cpp.

◆ formatDistance()

QString QgsDistanceArea::formatDistance ( double  distance,
int  decimals,
QgsUnitTypes::DistanceUnit  unit,
bool  keepBaseUnit = false 
)
static

Returns an distance formatted as a friendly string.

Parameters
distancedistance to format
decimalsnumber of decimal places to show
unitunit of distance
keepBaseUnitset to false to allow conversion of large distances to more suitable units, e.g., meters to kilometers
Returns
formatted distance string
Since
QGIS 2.16
See also
formatArea()

Definition at line 754 of file qgsdistancearea.cpp.

◆ lengthUnits()

QgsUnitTypes::DistanceUnit QgsDistanceArea::lengthUnits ( ) const

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

Since
QGIS 2.14
See also
areaUnits()

Definition at line 437 of file qgsdistancearea.cpp.

◆ measureArea()

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. The units for the returned area can be retrieved by calling areaUnits().
Since
QGIS 2.12
See also
measureLength()
measurePerimeter()
areaUnits()

Definition at line 180 of file qgsdistancearea.cpp.

◆ measureLength()

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().
Since
QGIS 2.12
See also
lengthUnits()
measureArea()
measurePerimeter()

Definition at line 189 of file qgsdistancearea.cpp.

◆ measureLine() [1/2]

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

◆ measureLine() [2/2]

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

Measures the distance between two points.

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

◆ measureLineProjected()

double QgsDistanceArea::measureLineProjected ( const QgsPoint p1,
double  distance = 1,
double  azimuth = M_PI / 2,
QgsPoint projectedPoint = nullptr 
) const

Calculates the distance from one point with distance in meters and azimuth (direction) When the sourceCrs() is geographic, computeSpheroidProject() will be called otherwise QgsPoint.project() will be called after QgsUnitTypes::fromUnitToUnitFactor() has been applied to the distance.

Note
: The input Point must be in the coordinate reference system being used
Since
QGIS 3.0
Parameters
p1start point [can be Cartesian or Geographic]
distancemust be in meters
azimuth- azimuth in radians, clockwise from North
projectedPointcalculated projected point
Returns
distance in mapUnits
See also
sourceCrs()
computeSpheroidProject()

Definition at line 347 of file qgsdistancearea.cpp.

◆ measurePerimeter()

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().
Since
QGIS 2.12
See also
lengthUnits()
measureArea()
measurePerimeter()

Definition at line 198 of file qgsdistancearea.cpp.

◆ measurePolygon()

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

Measures the area of the polygon described by a set of points.

Definition at line 463 of file qgsdistancearea.cpp.

◆ setEllipsoid() [1/2]

bool QgsDistanceArea::setEllipsoid ( const QString &  ellipsoid)

Sets the ellipsoid by its acronym.

Known ellipsoid acronyms can be retrieved using QgsEllipsoidUtils::acronyms(). Calculations will only use the ellipsoid if a valid ellipsoid has been set.

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

Definition at line 63 of file qgsdistancearea.cpp.

◆ setEllipsoid() [2/2]

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

Sets ellipsoid by supplied radii.

Calculations will only use the ellipsoid if a valid ellipsoid been set.

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

Definition at line 87 of file qgsdistancearea.cpp.

◆ setSourceCrs()

void QgsDistanceArea::setSourceCrs ( const QgsCoordinateReferenceSystem srcCRS)

Sets source spatial reference system.

Since
QGIS 2.2
See also
sourceCrs()

Definition at line 58 of file qgsdistancearea.cpp.

◆ sourceCrs()

QgsCoordinateReferenceSystem QgsDistanceArea::sourceCrs ( ) const
inline

Returns the source spatial reference system.

See also
setSourceCrs()

Definition at line 75 of file qgsdistancearea.h.

◆ willUseEllipsoid()

bool QgsDistanceArea::willUseEllipsoid ( ) const

Returns whether calculations will use the ellipsoid.

Calculations will only use the ellipsoid if a valid ellipsoid() has been set.

Since
QGIS 2.14
See also
ellipsoid()

Definition at line 53 of file qgsdistancearea.cpp.


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