2007-03-02 09:56:44 +00:00
|
|
|
|
|
|
|
class QgsDistanceArea
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsdistancearea.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
//! Constructor
|
|
|
|
QgsDistanceArea();
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! Destructor
|
|
|
|
~QgsDistanceArea();
|
2012-09-01 23:55:32 +02:00
|
|
|
|
2012-09-03 23:49:46 +02:00
|
|
|
//! Copy constructor
|
|
|
|
QgsDistanceArea( const QgsDistanceArea &origDA );
|
2012-09-01 23:55:32 +02:00
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** 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 setEllipsoid()
|
|
|
|
* @see willUseEllipsoid()
|
|
|
|
*/
|
2012-09-03 23:49:46 +02:00
|
|
|
void setEllipsoidalMode( bool flag );
|
2007-03-02 09:56:44 +00:00
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** Returns whether ellipsoidal calculations are enabled
|
|
|
|
* @see willUseEllipsoid()
|
|
|
|
* @see setEllipsoidalMode()
|
|
|
|
*/
|
2012-09-03 23:49:46 +02:00
|
|
|
bool ellipsoidalEnabled() const;
|
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** 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 ellipsoidalEnabled()
|
|
|
|
* @see ellipsoid()
|
|
|
|
*/
|
|
|
|
bool willUseEllipsoid() const;
|
|
|
|
|
2008-08-21 21:11:56 +00:00
|
|
|
//! sets source spatial reference system (by QGIS CRS)
|
2012-09-03 23:49:46 +02:00
|
|
|
void setSourceCrs( long srsid );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/**
|
|
|
|
* Sets source spatial reference system (by QGIS CRS)
|
|
|
|
* @note: missing in Python bindings in QGIS < 2.2
|
|
|
|
*/
|
2014-01-09 17:58:57 +01:00
|
|
|
void setSourceCrs( const QgsCoordinateReferenceSystem& srcCRS );
|
|
|
|
|
2011-02-22 23:32:33 +00:00
|
|
|
//! sets source spatial reference system by authid
|
2015-10-07 11:55:34 +11:00
|
|
|
void setSourceAuthId( const QString& authid );
|
2008-07-07 11:44:41 +00:00
|
|
|
|
2016-09-15 18:26:43 +10:00
|
|
|
/** Returns the source spatial reference system.
|
|
|
|
* @see setSourceCrs()
|
|
|
|
*/
|
|
|
|
QgsCoordinateReferenceSystem sourceCrs() const;
|
2016-02-05 20:12:16 +11:00
|
|
|
|
|
|
|
/** Returns the QgsCoordinateReferenceSystem::srsid() for the CRS used during calculations.
|
|
|
|
* @see setSourceCrs()
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
long sourceCrsId() const;
|
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! What sort of coordinate system is being used?
|
2014-01-27 09:22:24 +01:00
|
|
|
bool geographic() const;
|
2007-03-02 09:56:44 +00:00
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** 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 ellipsoid()
|
|
|
|
* @see setEllipsoidalMode()
|
|
|
|
* @see willUseEllipsoid()
|
|
|
|
*/
|
2012-09-03 23:49:46 +02:00
|
|
|
bool setEllipsoid( const QString& ellipsoid );
|
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** 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 ellipsoid()
|
|
|
|
* @see setEllipsoidalMode()
|
|
|
|
* @see willUseEllipsoid()
|
|
|
|
*/
|
2012-09-03 15:47:48 +02:00
|
|
|
// Inverse flattening is calculated with invf = a/(a-b)
|
|
|
|
bool setEllipsoid( double semiMajor, double semiMinor );
|
|
|
|
|
2016-02-03 16:59:49 +11:00
|
|
|
/** Returns ellipsoid's acronym. Calculations will only use the
|
|
|
|
* ellipsoid if ellipsoidalEnabled() is true and an ellipsoid has been set.
|
|
|
|
* @see setEllipsoid()
|
|
|
|
* @see ellipsoidalEnabled()
|
|
|
|
* @see willUseEllipsoid()
|
|
|
|
*/
|
2015-10-27 14:03:00 +11:00
|
|
|
QString ellipsoid() const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! returns ellipsoid's semi major axis
|
2014-01-27 09:22:24 +01:00
|
|
|
double ellipsoidSemiMajor() const;
|
2007-03-02 09:56:44 +00:00
|
|
|
//! returns ellipsoid's semi minor axis
|
2014-01-27 09:22:24 +01:00
|
|
|
double ellipsoidSemiMinor() const;
|
2007-03-02 09:56:44 +00:00
|
|
|
//! returns ellipsoid's inverse flattening
|
2014-01-27 09:22:24 +01:00
|
|
|
double ellipsoidInverseFlattening() const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2015-10-16 21:19:59 +11:00
|
|
|
/** Measures the area of a geometry.
|
|
|
|
* @param geometry geometry to measure
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* @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().
|
2015-10-16 21:19:59 +11:00
|
|
|
* @note added in QGIS 2.12
|
|
|
|
* @see measureLength()
|
|
|
|
* @see measurePerimeter()
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* @see areaUnits()
|
2015-10-16 21:19:59 +11:00
|
|
|
*/
|
|
|
|
double measureArea( const QgsGeometry* geometry ) const;
|
|
|
|
|
|
|
|
/** Measures the length of a geometry.
|
|
|
|
* @param geometry geometry to measure
|
2016-02-05 20:12:16 +11:00
|
|
|
* @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().
|
2015-10-16 21:19:59 +11:00
|
|
|
* @note added in QGIS 2.12
|
2016-02-05 20:12:16 +11:00
|
|
|
* @see lengthUnits()
|
2015-10-16 21:19:59 +11:00
|
|
|
* @see measureArea()
|
|
|
|
* @see measurePerimeter()
|
|
|
|
*/
|
|
|
|
double measureLength( const QgsGeometry* geometry ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2016-02-05 20:12:16 +11:00
|
|
|
/** Measures the perimeter of a polygon geometry.
|
|
|
|
* @param geometry geometry 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 lengthUnits()
|
|
|
|
* @see measureArea()
|
|
|
|
* @see measurePerimeter()
|
|
|
|
*/
|
|
|
|
double measurePerimeter( const QgsGeometry *geometry ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2016-02-05 20:12:16 +11:00
|
|
|
/** Measures the length of a line with multiple segments.
|
|
|
|
* @param points list of points in line
|
|
|
|
* @returns length of line. The units for the returned length can be retrieved by calling lengthUnits().
|
|
|
|
* @see lengthUnits()
|
|
|
|
*/
|
2015-05-14 20:03:13 +10:00
|
|
|
double measureLine( const QList<QgsPoint>& points ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2016-02-05 20:12:16 +11:00
|
|
|
/** Measures length of a line with one segment.
|
|
|
|
* @param p1 start of line
|
|
|
|
* @param p2 end of line
|
|
|
|
* @returns distance between points. The units for the returned distance can be retrieved by calling lengthUnits().
|
|
|
|
* @see lengthUnits()
|
|
|
|
*/
|
2015-05-14 20:03:13 +10:00
|
|
|
double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2016-02-05 20:12:16 +11:00
|
|
|
/** Returns the units of distance for length calculations made by this object.
|
|
|
|
* @note added in QGIS 2.14
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* @see areaUnits()
|
2016-02-05 20:12:16 +11:00
|
|
|
*/
|
2016-07-17 14:56:05 +10:00
|
|
|
QgsUnitTypes::DistanceUnit lengthUnits() const;
|
2016-02-05 20:12:16 +11:00
|
|
|
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
/** Returns the units of area for areal calculations made by this object.
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see lengthUnits()
|
|
|
|
*/
|
|
|
|
QgsUnitTypes::AreaUnit areaUnits() const;
|
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! measures polygon area
|
2015-05-14 20:03:13 +10:00
|
|
|
double measurePolygon( const QList<QgsPoint>& points ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! compute bearing - in radians
|
2015-05-14 20:03:13 +10:00
|
|
|
double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;
|
2007-03-02 09:56:44 +00:00
|
|
|
|
2016-02-28 08:35:02 +11:00
|
|
|
/** Returns an distance formatted as a friendly string.
|
|
|
|
* @param distance distance to format
|
|
|
|
* @param decimals number of decimal places to show
|
|
|
|
* @param unit unit of distance
|
|
|
|
* @param keepBaseUnit set to false to allow conversion of large distances to more suitable units, eg meters to
|
|
|
|
* kilometers
|
|
|
|
* @returns formatted distance string
|
|
|
|
* @note added in QGIS 2.16
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* @see formatArea()
|
|
|
|
*/
|
2016-07-17 14:56:05 +10:00
|
|
|
static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false );
|
2007-03-02 09:56:44 +00:00
|
|
|
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
/** Returns an area formatted as a friendly string.
|
|
|
|
* @param area area to format
|
|
|
|
* @param decimals number of decimal places to show
|
|
|
|
* @param unit unit of area
|
|
|
|
* @param keepBaseUnit set to false to allow conversion of large areas to more suitable units, eg square meters to
|
|
|
|
* square kilometers
|
|
|
|
* @returns formatted area string
|
|
|
|
* @note added in QGIS 2.14
|
2016-02-28 08:35:02 +11:00
|
|
|
* @see formatDistance()
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
*/
|
|
|
|
static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false );
|
|
|
|
|
2016-02-05 20:12:16 +11:00
|
|
|
/** Takes a length measurement calculated by this QgsDistanceArea object and converts it to a
|
|
|
|
* different distance unit.
|
|
|
|
* @param length length value calculated by this class to convert. It is assumed that the length
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* was calculated by this class, ie that its unit of length is equal to lengthUnits().
|
2016-02-05 20:12:16 +11:00
|
|
|
* @param toUnits distance unit to convert measurement to
|
|
|
|
* @returns converted distance
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
* @see convertAreaMeasurement()
|
|
|
|
* @note added in QGIS 2.14
|
2016-02-05 20:12:16 +11:00
|
|
|
*/
|
2016-07-17 14:56:05 +10:00
|
|
|
double convertLengthMeasurement( double length, QgsUnitTypes::DistanceUnit toUnits ) const;
|
2016-02-05 20:12:16 +11:00
|
|
|
|
Fix project unit confusion (pt 3): add area unit settings with a
ton of available area units (eg m2, km2, mi2, ft2, yd2, ha, ac,
etc)
Adds a new option in both the QGIS setting and project properties to
set the units used for area measurements. Just like the distance
setting, this defaults to the units set in QGIS options, but can
then be overridden for specific projects.
The setting is respected for area calculations in:
- Attribute table field update bar
- Field calculator calculations
- Identify tool derived length and perimeter values
Also adds unit tests to ensure that area calculated by attribute table
update bar, field calculator and identify tool are consistent wrt
ellipsoidal calculations and area units.
TODO: make measure tool respect area setting
(refs #13209, #4252 and fixes #12939, #2402, #4857)
2016-02-15 07:25:32 +11:00
|
|
|
/** Takes an area measurement calculated by this QgsDistanceArea object and converts it to a
|
|
|
|
* different areal unit.
|
|
|
|
* @param area area 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().
|
|
|
|
* @param toUnits area unit to convert measurement to
|
|
|
|
* @returns converted area
|
|
|
|
* @see convertLengthMeasurement()
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
double convertAreaMeasurement( double area, QgsUnitTypes::AreaUnit toUnits ) const;
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
protected:
|
|
|
|
//! measures polygon area and perimeter, vertices are extracted from WKB
|
2016-02-05 20:12:16 +11:00
|
|
|
// @note not available in python bindings
|
2016-02-14 03:50:23 +01:00
|
|
|
// QgsConstWkbPtr measurePolygon( QgsConstWkbPtr feature, double* area, double* perimeter, bool hasZptr = false ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
/**
|
2016-02-14 03:50:23 +01:00
|
|
|
* 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)
|
|
|
|
* @return distance in meters
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
|
|
|
double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
|
2016-02-14 03:50:23 +01:00
|
|
|
double* course1 = 0, double* course2 = 0 ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2014-06-10 16:23:02 +07:00
|
|
|
//! uses flat / planimetric / Euclidean distance
|
2015-05-14 20:03:13 +10:00
|
|
|
double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;
|
2014-06-10 16:23:02 +07:00
|
|
|
|
|
|
|
//! calculate distance with given coordinates (does not do a transform anymore)
|
2015-05-14 20:03:13 +10:00
|
|
|
double computeDistance( const QList<QgsPoint>& points ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
/**
|
2016-02-14 03:50:23 +01:00
|
|
|
* calculates area of polygon on ellipsoid
|
|
|
|
* algorithm has been taken from GRASS: gis/area_poly1.c
|
|
|
|
*/
|
2015-05-14 20:03:13 +10:00
|
|
|
double computePolygonArea( const QList<QgsPoint>& points ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-05-14 20:03:13 +10:00
|
|
|
double computePolygonFlatArea( const QList<QgsPoint>& points ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
/**
|
2016-02-14 03:50:23 +01:00
|
|
|
* precalculates some values
|
|
|
|
* (must be called always when changing ellipsoid)
|
|
|
|
*/
|
2014-05-27 23:22:50 +02:00
|
|
|
void computeAreaInit();
|
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
};
|