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
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! returns source spatial reference system
|
2014-01-27 09:22:24 +01:00
|
|
|
long sourceCrs() 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
|
|
|
/** General measurement (line distance or polygon area)
|
|
|
|
* @deprecated use measureArea() or measureLength() methods instead, as this method
|
|
|
|
* is unpredictable for geometry collections
|
|
|
|
*/
|
|
|
|
double measure( const QgsGeometry* geometry ) const /Deprecated/;
|
|
|
|
|
|
|
|
/** Measures the area of a geometry.
|
|
|
|
* @param geometry geometry to measure
|
|
|
|
* @returns area of geometry. For geometry collections, non surface geometries will be ignored
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
* @see measureLength()
|
|
|
|
* @see measurePerimeter()
|
|
|
|
*/
|
|
|
|
double measureArea( const QgsGeometry* geometry ) const;
|
|
|
|
|
|
|
|
/** Measures the length of a geometry.
|
|
|
|
* @param geometry geometry to measure
|
|
|
|
* @returns length of geometry. For geometry collections, non curve geometries will be ignored
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
* @see measureArea()
|
|
|
|
* @see measurePerimeter()
|
|
|
|
*/
|
|
|
|
double measureLength( const QgsGeometry* geometry ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
|
|
|
//! measures perimeter of polygon
|
2015-05-14 20:03:13 +10:00
|
|
|
double measurePerimeter( const QgsGeometry* geometry ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
|
|
|
//! measures line
|
2015-05-14 20:03:13 +10:00
|
|
|
double measureLine( const QList<QgsPoint>& points ) const;
|
2012-09-03 23:49:46 +02:00
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
//! measures line with one segment
|
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
|
|
|
|
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
|
|
|
|
2010-09-04 13:08:17 +00:00
|
|
|
static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );
|
2007-03-02 09:56:44 +00:00
|
|
|
|
2012-08-20 22:51:32 +02:00
|
|
|
//! Helper for conversion between physical units
|
2015-05-14 20:03:13 +10:00
|
|
|
void convertMeasurement( double &measure /In,Out/, QGis::UnitType &measureUnits /In,Out/, QGis::UnitType displayUnits, bool isArea ) const;
|
2012-08-20 22:51:32 +02:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
protected:
|
|
|
|
//! measures line distance, line points are extracted from WKB
|
|
|
|
// @note available in python bindings
|
2015-05-14 20:03:13 +10:00
|
|
|
// const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false ) const;
|
2014-05-27 23:22:50 +02:00
|
|
|
//! measures polygon area and perimeter, vertices are extracted from WKB
|
|
|
|
// @note available in python bindings
|
2015-05-14 20:03:13 +10:00
|
|
|
// const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;
|
2014-05-27 23:22:50 +02: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
|
|
|
|
*/
|
|
|
|
double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
|
2015-05-14 20:03:13 +10:00
|
|
|
double* course1 = NULL, double* course2 = NULL ) 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
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
precalculates some values
|
|
|
|
(must be called always when changing ellipsoid)
|
|
|
|
*/
|
|
|
|
void computeAreaInit();
|
|
|
|
|
2007-03-02 09:56:44 +00:00
|
|
|
};
|