Skip to content
Permalink
Browse files

Const correctness for QgsDistanceArea

  • Loading branch information
nyalldawson committed May 14, 2015
1 parent 5194ce5 commit c5bc778b1d9b09f993ec13b675b6e4f3c37f50d2
Showing with 46 additions and 46 deletions.
  1. +14 −14 python/core/qgsdistancearea.sip
  2. +16 −16 src/core/qgsdistancearea.cpp
  3. +16 −16 src/core/qgsdistancearea.h
@@ -56,35 +56,35 @@ class QgsDistanceArea
double ellipsoidInverseFlattening() const;

//! general measurement (line distance or polygon area)
double measure( const QgsGeometry* geometry );
double measure( const QgsGeometry* geometry ) const;

//! measures perimeter of polygon
double measurePerimeter( const QgsGeometry* geometry );
double measurePerimeter( const QgsGeometry* geometry ) const;

//! measures line
double measureLine( const QList<QgsPoint>& points );
double measureLine( const QList<QgsPoint>& points ) const;

//! measures line with one segment
double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;

//! measures polygon area
double measurePolygon( const QList<QgsPoint>& points );
double measurePolygon( const QList<QgsPoint>& points ) const;

//! compute bearing - in radians
double bearing( const QgsPoint& p1, const QgsPoint& p2 );
double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;

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

//! Helper for conversion between physical units
void convertMeasurement( double &measure /In,Out/, QGis::UnitType &measureUnits /In,Out/, QGis::UnitType displayUnits, bool isArea );
void convertMeasurement( double &measure /In,Out/, QGis::UnitType &measureUnits /In,Out/, QGis::UnitType displayUnits, bool isArea ) const;

protected:
//! measures line distance, line points are extracted from WKB
// @note available in python bindings
// const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false );
// const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false ) const;
//! measures polygon area and perimeter, vertices are extracted from WKB
// @note available in python bindings
// const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
// const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;

/**
calculates distance from two points on ellipsoid
@@ -97,22 +97,22 @@ class QgsDistanceArea
@return distance in meters
*/
double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
double* course1 = NULL, double* course2 = NULL );
double* course1 = NULL, double* course2 = NULL ) const;

//! uses flat / planimetric / Euclidean distance
double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 );
double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;

//! calculate distance with given coordinates (does not do a transform anymore)
double computeDistance( const QList<QgsPoint>& points );
double computeDistance( const QList<QgsPoint>& points ) const;

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

*/
double computePolygonArea( const QList<QgsPoint>& points );
double computePolygonArea( const QList<QgsPoint>& points ) const;

double computePolygonFlatArea( const QList<QgsPoint>& points );
double computePolygonFlatArea( const QList<QgsPoint>& points ) const;

/**
precalculates some values
@@ -254,7 +254,7 @@ bool QgsDistanceArea::setEllipsoid( double semiMajor, double semiMinor )
return true;
}

double QgsDistanceArea::measure( const QgsGeometry *geometry )
double QgsDistanceArea::measure( const QgsGeometry *geometry ) const
{
if ( !geometry )
return 0.0;
@@ -329,7 +329,7 @@ double QgsDistanceArea::measure( const QgsGeometry *geometry )
}
}

double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry )
double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry ) const
{
if ( !geometry )
return 0.0;
@@ -389,7 +389,7 @@ double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry )
}


const unsigned char* QgsDistanceArea::measureLine( const unsigned char* feature, double* area, bool hasZptr )
const unsigned char* QgsDistanceArea::measureLine( const unsigned char* feature, double* area, bool hasZptr ) const
{
QgsConstWkbPtr wkbPtr( feature + 1 + sizeof( int ) );
int nPoints;
@@ -416,7 +416,7 @@ const unsigned char* QgsDistanceArea::measureLine( const unsigned char* feature,
return wkbPtr;
}

double QgsDistanceArea::measureLine( const QList<QgsPoint> &points )
double QgsDistanceArea::measureLine( const QList<QgsPoint> &points ) const
{
if ( points.size() < 2 )
return 0;
@@ -458,7 +458,7 @@ double QgsDistanceArea::measureLine( const QList<QgsPoint> &points )

}

double QgsDistanceArea::measureLine( const QgsPoint &p1, const QgsPoint &p2 )
double QgsDistanceArea::measureLine( const QgsPoint &p1, const QgsPoint &p2 ) const
{
double result;

@@ -494,7 +494,7 @@ double QgsDistanceArea::measureLine( const QgsPoint &p1, const QgsPoint &p2 )
}


const unsigned char *QgsDistanceArea::measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr )
const unsigned char *QgsDistanceArea::measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr ) const
{
if ( !feature )
{
@@ -589,7 +589,7 @@ const unsigned char *QgsDistanceArea::measurePolygon( const unsigned char* featu
}


double QgsDistanceArea::measurePolygon( const QList<QgsPoint>& points )
double QgsDistanceArea::measurePolygon( const QList<QgsPoint>& points ) const
{
try
{
@@ -616,7 +616,7 @@ double QgsDistanceArea::measurePolygon( const QList<QgsPoint>& points )
}


double QgsDistanceArea::bearing( const QgsPoint& p1, const QgsPoint& p2 )
double QgsDistanceArea::bearing( const QgsPoint& p1, const QgsPoint& p2 ) const
{
QgsPoint pp1 = p1, pp2 = p2;
double bearing;
@@ -643,7 +643,7 @@ double QgsDistanceArea::bearing( const QgsPoint& p1, const QgsPoint& p2 )

double QgsDistanceArea::computeDistanceBearing(
const QgsPoint& p1, const QgsPoint& p2,
double* course1, double* course2 )
double* course1, double* course2 ) const
{
if ( p1.x() == p2.x() && p1.y() == p2.y() )
return 0;
@@ -718,12 +718,12 @@ double QgsDistanceArea::computeDistanceBearing(
return s;
}

double QgsDistanceArea::computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 )
double QgsDistanceArea::computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const
{
return sqrt(( p2.x() - p1.x() ) * ( p2.x() - p1.x() ) + ( p2.y() - p1.y() ) * ( p2.y() - p1.y() ) );
}

double QgsDistanceArea::computeDistance( const QList<QgsPoint>& points )
double QgsDistanceArea::computeDistance( const QList<QgsPoint>& points ) const
{
if ( points.size() < 2 )
return 0;
@@ -767,7 +767,7 @@ double QgsDistanceArea::computeDistance( const QList<QgsPoint>& points )
// don't know how does it work, but it's working .)
// see G_begin_ellipsoid_polygon_area() in area_poly1.c

double QgsDistanceArea::getQ( double x )
double QgsDistanceArea::getQ( double x ) const
{
double sinx, sinx2;

@@ -778,7 +778,7 @@ double QgsDistanceArea::getQ( double x )
}


double QgsDistanceArea::getQbar( double x )
double QgsDistanceArea::getQbar( double x ) const
{
double cosx, cosx2;

@@ -824,7 +824,7 @@ void QgsDistanceArea::computeAreaInit()
}


double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points )
double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points ) const
{
double x1, y1, x2, y2, dx, dy;
double Qbar1, Qbar2;
@@ -881,7 +881,7 @@ double QgsDistanceArea::computePolygonArea( const QList<QgsPoint>& points )
return area;
}

double QgsDistanceArea::computePolygonFlatArea( const QList<QgsPoint>& points )
double QgsDistanceArea::computePolygonFlatArea( const QList<QgsPoint>& points ) const
{
// Normal plane area calculations.
double area = 0.0;
@@ -1031,7 +1031,7 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,
return QLocale::system().toString( value, 'f', decimals ) + unitLabel;
}

void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea )
void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const
{
// Helper for converting between meters and feet and degrees and NauticalMiles...
// The parameters measure and measureUnits are in/out
@@ -87,35 +87,35 @@ class CORE_EXPORT QgsDistanceArea
double ellipsoidInverseFlattening() const { return mInvFlattening; }

//! general measurement (line distance or polygon area)
double measure( const QgsGeometry* geometry );
double measure( const QgsGeometry* geometry ) const;

//! measures perimeter of polygon
double measurePerimeter( const QgsGeometry *geometry );
double measurePerimeter( const QgsGeometry *geometry ) const;

//! measures line
double measureLine( const QList<QgsPoint>& points );
double measureLine( const QList<QgsPoint>& points ) const;

//! measures line with one segment
double measureLine( const QgsPoint& p1, const QgsPoint& p2 );
double measureLine( const QgsPoint& p1, const QgsPoint& p2 ) const;

//! measures polygon area
double measurePolygon( const QList<QgsPoint>& points );
double measurePolygon( const QList<QgsPoint>& points ) const;

//! compute bearing - in radians
double bearing( const QgsPoint& p1, const QgsPoint& p2 );
double bearing( const QgsPoint& p1, const QgsPoint& p2 ) const;

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

//! Helper for conversion between physical units
void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea );
void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const;

protected:
//! measures line distance, line points are extracted from WKB
// @note available in python bindings
const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false );
const unsigned char* measureLine( const unsigned char* feature, double* area, bool hasZptr = false ) const;
//! measures polygon area and perimeter, vertices are extracted from WKB
// @note available in python bindings
const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false );
const unsigned char* measurePolygon( const unsigned char* feature, double* area, double* perimeter, bool hasZptr = false ) const;

/**
calculates distance from two points on ellipsoid
@@ -128,22 +128,22 @@ class CORE_EXPORT QgsDistanceArea
@return distance in meters
*/
double computeDistanceBearing( const QgsPoint& p1, const QgsPoint& p2,
double* course1 = NULL, double* course2 = NULL );
double* course1 = NULL, double* course2 = NULL ) const;

//! uses flat / planimetric / Euclidean distance
double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 );
double computeDistanceFlat( const QgsPoint& p1, const QgsPoint& p2 ) const;

//! calculate distance with given coordinates (does not do a transform anymore)
double computeDistance( const QList<QgsPoint>& points );
double computeDistance( const QList<QgsPoint>& points ) const;

/**
calculates area of polygon on ellipsoid
algorithm has been taken from GRASS: gis/area_poly1.c
*/
double computePolygonArea( const QList<QgsPoint>& points );
double computePolygonArea( const QList<QgsPoint>& points ) const;

double computePolygonFlatArea( const QList<QgsPoint>& points );
double computePolygonFlatArea( const QList<QgsPoint>& points ) const;

/**
precalculates some values
@@ -169,8 +169,8 @@ class CORE_EXPORT QgsDistanceArea

// utility functions for polygon area measurement

double getQ( double x );
double getQbar( double x );
double getQ( double x ) const;
double getQbar( double x ) const;

// temporary area measurement stuff

0 comments on commit c5bc778

Please sign in to comment.
You can’t perform that action at this time.