Skip to content
Permalink
Browse files

Rename member variables, remove "forceCartesian" arguments

  • Loading branch information
jdugge authored and nyalldawson committed Jan 6, 2019
1 parent bf5a077 commit c09b379fc723d2b41badcb0a90cfca78793e0a51
@@ -189,25 +189,23 @@ Measures the perimeter of a polygon geometry.
.. versionadded:: 2.12
%End

double measureLine( const QVector<QgsPointXY> &points, bool forceCartesian = false ) const;
double measureLine( const QVector<QgsPointXY> &points ) const;
%Docstring
Measures the length of a line with multiple segments.

:param points: list of points in line
:param forceCartesian: calculate distances in Cartesian coordinates

:return: length of line. The units for the returned length can be retrieved by calling lengthUnits().

.. seealso:: :py:func:`lengthUnits`
%End

double measureLine( const QgsPointXY &p1, const QgsPointXY &p2, bool forceCartesian = false ) const;
double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const;
%Docstring
Measures the distance between two points.

:param p1: start of line
:param p2: end of line
:param forceCartesian: calculate distances in Cartesian coordinates

:return: distance between points. The units for the returned distance can be retrieved by calling lengthUnits().

@@ -52,14 +52,14 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool *tool, Qt::WindowFlags f )
repopulateComboBoxUnits( mMeasureArea );
if ( mMeasureArea )
{
if ( useMapUnits )
if ( mUseMapUnits )
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsUnitTypes::AreaUnknownUnit ) );
else
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsProject::instance()->areaUnits() ) );
}
else
{
if ( useMapUnits )
if ( mUseMapUnits )
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsUnitTypes::DistanceUnknownUnit ) );
else
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsProject::instance()->distanceUnits() ) );
@@ -113,7 +113,7 @@ void QgsMeasureDialog::updateSettings()
mCanvasUnits = mCanvas->mapUnits();
// Configure QgsDistanceArea
mDistanceUnits = QgsProject::instance()->distanceUnits();
mapDistanceUnits = QgsProject::instance()->crs().mapUnits();
mMapDistanceUnits = QgsProject::instance()->crs().mapUnits();
mAreaUnits = QgsProject::instance()->areaUnits();
mDa.setSourceCrs( mCanvas->mapSettings().destinationCrs(), QgsProject::instance()->transformContext() );
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
@@ -125,9 +125,15 @@ void QgsMeasureDialog::updateSettings()
if ( !mCanvas->mapSettings().destinationCrs().isValid() ||
( mCanvas->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees
&& mDistanceUnits == QgsUnitTypes::DistanceDegrees ) )
forceCartesian = true;
{
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
}
else
forceCartesian = false;
{
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
mForceCartesian = false;
}
}

void QgsMeasureDialog::unitsChanged( int index )
@@ -137,25 +143,25 @@ void QgsMeasureDialog::unitsChanged( int index )
mAreaUnits = static_cast< QgsUnitTypes::AreaUnit >( mUnitsCombo->itemData( index ).toInt() );
if ( mAreaUnits == QgsUnitTypes::AreaUnknownUnit )
{
useMapUnits = true;
mAreaUnits = QgsUnitTypes::distanceToAreaUnit( mapDistanceUnits );
mUseMapUnits = true;
mAreaUnits = QgsUnitTypes::distanceToAreaUnit( mMapDistanceUnits );
}
else
{
useMapUnits = false;
mUseMapUnits = false;
}
}
else
{
mDistanceUnits = static_cast< QgsUnitTypes::DistanceUnit >( mUnitsCombo->itemData( index ).toInt() );
if ( mDistanceUnits == QgsUnitTypes::DistanceUnknownUnit )
{
useMapUnits = true;
mDistanceUnits = mapDistanceUnits;
mUseMapUnits = true;
mDistanceUnits = mMapDistanceUnits;
}
else
{
useMapUnits = false;
mUseMapUnits = false;
}
}
mTable->clear();
@@ -185,9 +191,15 @@ void QgsMeasureDialog::mouseMove( const QgsPointXY &point )
if ( !mCanvas->mapSettings().destinationCrs().isValid() ||
( mCanvas->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees
&& mDistanceUnits == QgsUnitTypes::DistanceDegrees ) )
forceCartesian = true;
{
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
}
else
forceCartesian = false;
{
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
mForceCartesian = false;
}

mLastMousePoint = point;
// show current distance/area while moving the point
@@ -204,9 +216,9 @@ void QgsMeasureDialog::mouseMove( const QgsPointXY &point )
{
QVector< QgsPointXY > tmpPoints = mTool->points();
QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) ), p2( point );
double d = mDa.measureLine( p1, p2, forceCartesian );
editTotal->setText( formatDistance( mTotal + d, !forceCartesian ) );
if ( !forceCartesian )
double d = mDa.measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d, !mForceCartesian ) );
if ( !mForceCartesian )
d = convertLength( d, mDistanceUnits );

// Set moving
@@ -237,8 +249,8 @@ void QgsMeasureDialog::addPoint()
}
if ( numPoints > 1 )
{
mTotal = mDa.measureLine( mTool->points(), forceCartesian );
editTotal->setText( formatDistance( mTotal, !forceCartesian ) );
mTotal = mDa.measureLine( mTool->points() );
editTotal->setText( formatDistance( mTotal, !mForceCartesian ) );
}
}
}
@@ -265,14 +277,14 @@ void QgsMeasureDialog::removeLastPoint()
//remove final row
delete mTable->takeTopLevelItem( mTable->topLevelItemCount() - 1 );

mTotal = mDa.measureLine( mTool->points(), forceCartesian );
mTotal = mDa.measureLine( mTool->points() );

if ( !mTool->done() )
{
// need to add the distance for the temporary mouse cursor point
QVector< QgsPointXY > tmpPoints = mTool->points();
QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) );
double d = mDa.measureLine( p1, mLastMousePoint, forceCartesian );
double d = mDa.measureLine( p1, mLastMousePoint );

d = convertLength( d, mDistanceUnits );

@@ -282,7 +294,7 @@ void QgsMeasureDialog::removeLastPoint()
}
else
{
editTotal->setText( formatDistance( mTotal, !forceCartesian ) );
editTotal->setText( formatDistance( mTotal, !mForceCartesian ) );
}
}
}
@@ -346,7 +358,8 @@ void QgsMeasureDialog::updateUi()
// Set tooltip to indicate how we calculate measurements
QString toolTip = tr( "The calculations are based on:" );

bool forceCartesian = false;
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
mForceCartesian = false;
bool convertToDisplayUnits = true;

if ( mMeasureArea )
@@ -356,7 +369,8 @@ void QgsMeasureDialog::updateUi()
// no CRS => no units, newb!
toolTip += "<br> * " + tr( "No map projection set, so area is calculated using Cartesian calculations." );
toolTip += "<br> * " + tr( "Units are unknown." );
forceCartesian = true;
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
convertToDisplayUnits = false;
}
else if ( mCanvas->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees
@@ -365,7 +379,8 @@ void QgsMeasureDialog::updateUi()
//both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg(
mCanvas->mapSettings().destinationCrs().description() );
forceCartesian = true;
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
convertToDisplayUnits = false; //not required since we will be measuring in degrees
}
else
@@ -426,7 +441,8 @@ void QgsMeasureDialog::updateUi()
// no CRS => no units, newb!
toolTip += "<br> * " + tr( "No map projection set, so distance is calculated using Cartesian calculations." );
toolTip += "<br> * " + tr( "Units are unknown." );
forceCartesian = true;
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
convertToDisplayUnits = false;
}
else if ( mCanvas->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees
@@ -435,7 +451,8 @@ void QgsMeasureDialog::updateUi()
//both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg(
mCanvas->mapSettings().destinationCrs().description() );
forceCartesian = true;
mDa.setEllipsoid( GEO_NONE );
mForceCartesian = true;
convertToDisplayUnits = false; //not required since we will be measuring in degrees
}
else
@@ -496,17 +513,17 @@ void QgsMeasureDialog::updateUi()

if ( mMeasureArea )
{
if ( useMapUnits )
if ( mUseMapUnits )
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsUnitTypes::AreaUnknownUnit ) );
else
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( mAreaUnits ) );
}
else
{
if ( useMapUnits )
if ( mUseMapUnits )
{
mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( QgsUnitTypes::DistanceUnknownUnit ) );
mTable->setHeaderLabels( QStringList( tr( "Segments [%1]" ).arg( QgsUnitTypes::toString( mapDistanceUnits ) ) ) );
mTable->setHeaderLabels( QStringList( tr( "Segments [%1]" ).arg( QgsUnitTypes::toString( mMapDistanceUnits ) ) ) );
}
else
{
@@ -542,11 +559,11 @@ void QgsMeasureDialog::updateUi()
if ( !b )
{
double d = -1;
d = mDa.measureLine( p1, p2, forceCartesian );
if ( !forceCartesian )
d = mDa.measureLine( p1, p2 );
if ( !mForceCartesian )
{
if ( mDistanceUnits == QgsUnitTypes::DistanceUnknownUnit && mapDistanceUnits != QgsUnitTypes::DistanceUnknownUnit )
d = convertLength( d, mapDistanceUnits );
if ( mDistanceUnits == QgsUnitTypes::DistanceUnknownUnit && mMapDistanceUnits != QgsUnitTypes::DistanceUnknownUnit )
d = convertLength( d, mMapDistanceUnits );
else
d = convertLength( d, mDistanceUnits );
}
@@ -560,7 +577,7 @@ void QgsMeasureDialog::updateUi()
b = false;
}

mTotal = mDa.measureLine( mTool->points(), forceCartesian );
mTotal = mDa.measureLine( mTool->points() );
mTable->show(); // Show the table with items
editTotal->setText( formatDistance( mTotal, convertToDisplayUnits ) );
}
@@ -99,13 +99,13 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
bool mMeasureArea = false;

//! Indicates whether the user chose "Map units" instead of directly selecting a unit
bool useMapUnits = false;
bool mUseMapUnits = false;

/**
* Indicates whether we need to measure distances in Cartesian instead of
* spherical coordinates, such as when measuring in degrees in a geographic CRS
*/
bool forceCartesian = true;
bool mForceCartesian = true;

//! Number of decimal places we want.
int mDecimalPlaces = 3;
@@ -117,7 +117,7 @@ class APP_EXPORT QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
QgsUnitTypes::DistanceUnit mDistanceUnits = QgsUnitTypes::DistanceUnknownUnit;

//! Current map unit for distance values
QgsUnitTypes::DistanceUnit mapDistanceUnits = QgsUnitTypes::DistanceUnknownUnit;
QgsUnitTypes::DistanceUnit mMapDistanceUnits = QgsUnitTypes::DistanceUnknownUnit;

//! Current unit for area values
QgsUnitTypes::AreaUnit mAreaUnits = QgsUnitTypes::AreaUnknownUnit;
@@ -253,7 +253,7 @@ double QgsDistanceArea::measurePerimeter( const QgsGeometry &geometry ) const
return length;
}

double QgsDistanceArea::measureLine( const QgsCurve *curve, bool forceCartesian ) const
double QgsDistanceArea::measureLine( const QgsCurve *curve ) const
{
if ( !curve )
{
@@ -264,10 +264,10 @@ double QgsDistanceArea::measureLine( const QgsCurve *curve, bool forceCartesian
QVector<QgsPointXY> linePoints;
curve->points( linePointsV2 );
QgsGeometry::convertPointList( linePointsV2, linePoints );
return measureLine( linePoints, forceCartesian );
return measureLine( linePoints );
}

double QgsDistanceArea::measureLine( const QVector<QgsPointXY> &points, bool forceCartesian ) const
double QgsDistanceArea::measureLine( const QVector<QgsPointXY> &points ) const
{
if ( points.size() < 2 )
return 0;
@@ -277,22 +277,22 @@ double QgsDistanceArea::measureLine( const QVector<QgsPointXY> &points, bool for

try
{
if ( willUseEllipsoid() && !forceCartesian )
if ( willUseEllipsoid() )
p1 = mCoordTransform.transform( points[0] );
else
p1 = points[0];

for ( QVector<QgsPointXY>::const_iterator i = points.constBegin(); i != points.constEnd(); ++i )
{
if ( willUseEllipsoid() && !forceCartesian )
if ( willUseEllipsoid() )
{
p2 = mCoordTransform.transform( *i );
total += computeDistanceBearing( p1, p2 );
}
else
{
p2 = *i;
total += measureLine( p1, p2, forceCartesian );
total += measureLine( p1, p2 );
}

p1 = p2;
@@ -309,7 +309,7 @@ double QgsDistanceArea::measureLine( const QVector<QgsPointXY> &points, bool for

}

double QgsDistanceArea::measureLine( const QgsPointXY &p1, const QgsPointXY &p2, bool forceCartesian ) const
double QgsDistanceArea::measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const
{
double result;

@@ -318,7 +318,7 @@ double QgsDistanceArea::measureLine( const QgsPointXY &p1, const QgsPointXY &p2,
QgsPointXY pp1 = p1, pp2 = p2;

QgsDebugMsgLevel( QStringLiteral( "Measuring from %1 to %2" ).arg( p1.toString( 4 ), p2.toString( 4 ) ), 3 );
if ( willUseEllipsoid() && !forceCartesian )
if ( willUseEllipsoid() )
{
QgsDebugMsgLevel( QStringLiteral( "Ellipsoidal calculations is enabled, using ellipsoid %1" ).arg( mEllipsoid ), 4 );
QgsDebugMsgLevel( QStringLiteral( "From proj4 : %1" ).arg( mCoordTransform.sourceCrs().toProj4() ), 4 );
@@ -165,21 +165,19 @@ class CORE_EXPORT QgsDistanceArea
/**
* Measures the length of a line with multiple segments.
* \param points list of points in line
* \param forceCartesian calculate distances in Cartesian coordinates
* \returns length of line. The units for the returned length can be retrieved by calling lengthUnits().
* \see lengthUnits()
*/
double measureLine( const QVector<QgsPointXY> &points, bool forceCartesian = false ) const;
double measureLine( const QVector<QgsPointXY> &points ) const;

/**
* Measures the distance between two points.
* \param p1 start of line
* \param p2 end of line
* \param forceCartesian calculate distances in Cartesian coordinates
* \returns distance between points. The units for the returned distance can be retrieved by calling lengthUnits().
* \see lengthUnits()
*/
double measureLine( const QgsPointXY &p1, const QgsPointXY &p2, bool forceCartesian = false ) const;
double measureLine( const QgsPointXY &p1, const QgsPointXY &p2 ) const;

/**
* Calculates the distance from one point with distance in meters and azimuth (direction)
@@ -343,7 +341,7 @@ class CORE_EXPORT QgsDistanceArea
double getQbar( double x ) const;

double measure( const QgsAbstractGeometry *geomV2, MeasureType type = Default ) const;
double measureLine( const QgsCurve *curve, bool forceCartesian = false ) const;
double measureLine( const QgsCurve *curve ) const;
double measurePolygon( const QgsCurve *curve ) const;

// temporary area measurement stuff

0 comments on commit c09b379

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