Skip to content
Permalink
Browse files

[FEATURE][API] allow display in degrees, decimal minutes

- store degree format setting in project file
- [API] drop degree formats in unit type
  • Loading branch information
jef-n committed Aug 1, 2012
1 parent 5a43d74 commit 93e0a43055bf17b26820d06840857aaae471190b
@@ -72,17 +72,20 @@ public:

/** Map units that qgis supports
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
* @note that QGIS > 1.8 api returns to that
*/
enum UnitType
{
Meters = 0,
Feet = 1,
Degrees = 2, //for 1.0 api backwards compatibility
Degrees = 2,
UnknownUnit = 3,

// for [1.4;1.8] api backwards compatibility
DecimalDegrees = 2,
DegreesMinutesSeconds = 4,
DegreesDecimalMinutes = 5,
UnknownUnit = 3
} ;
DegreesMinutesSeconds = 2,
DegreesDecimalMinutes = 2,
};

//! User defined event types
enum UserEvent
@@ -5025,14 +5025,22 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
}
else
{
if ( mMapCanvas->mapUnits() == QGis::DegreesMinutesSeconds )
if ( mMapCanvas->mapUnits() == QGis::Degrees )
{
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );

if ( format == "DM" )
mCoordsEdit->setText( p.toDegreesMinutes( mMousePrecisionDecimalPlaces ) );
else if ( format == "DMS" )
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
else
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
}
else
{
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
}

if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
{
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
@@ -230,8 +230,6 @@ void QgsMeasureDialog::updateUi()
case QGis::Feet:
mTable->setHeaderLabels( QStringList( tr( "Segments (in feet)" ) ) );
break;
case QGis::DegreesMinutesSeconds:
case QGis::DegreesDecimalMinutes:
case QGis::Degrees:
mTable->setHeaderLabels( QStringList( tr( "Segments (in degrees)" ) ) );
break;
@@ -69,7 +69,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
//see if the user wants on the fly projection enabled
bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled();
cbxProjectionEnabled->setChecked( myProjectionEnabled );
btnGrpMapUnits->setEnabled( !myProjectionEnabled );

mProjectSrsId = myRenderer->destinationCrs().srsid();
QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) );
@@ -100,6 +99,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" );
spinBoxDP->setValue( dp );

QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );
if ( format == "DM" )
radDM->setChecked( true );
else if ( format == "DMS" )
radDMS->setChecked( true );
else
radD->setChecked( true );

//get the color selections and set the button color accordingly
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
@@ -328,22 +335,11 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
{
unit = QGis::Meters;
}
if ( unit == QGis::Meters )
{
radMeters->setChecked( true );
}
else if ( unit == QGis::Feet )
{
radFeet->setChecked( true );
}
else if ( unit == QGis::DegreesMinutesSeconds )
{
radDMS->setChecked( true );
}
else
{
radDecimalDegrees->setChecked( true );
}

radMeters->setChecked( unit == QGis::Meters );
radFeet->setChecked( unit == QGis::Feet );
radDegrees->setChecked( unit == QGis::Degrees );

mMapCanvas->mapRenderer()->setMapUnits( unit );
}

@@ -369,21 +365,17 @@ void QgsProjectProperties::apply()
// Note. Qt 3.2.3 and greater have a function selectedId() that
// can be used instead of the two part technique here
QGis::UnitType mapUnit;
if ( radMeters->isChecked() )
if ( radDegrees->isChecked() )
{
mapUnit = QGis::Meters;
mapUnit = QGis::Degrees;
}
else if ( radFeet->isChecked() )
{
mapUnit = QGis::Feet;
}
else if ( radDMS->isChecked() )
{
mapUnit = QGis::DegreesMinutesSeconds;
}
else
{
mapUnit = QGis::Degrees;
mapUnit = QGis::Meters;
}

QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
@@ -423,6 +415,9 @@ void QgsProjectProperties::apply()
// can be used instead of the two part technique here
QgsProject::instance()->writeEntry( "PositionPrecision", "/Automatic", radAutomatic->isChecked() );
QgsProject::instance()->writeEntry( "PositionPrecision", "/DecimalPlaces", spinBoxDP->value() );
QgsProject::instance()->writeEntry( "PositionPrecision", "/DegreeFormat",
QString( radDM->isChecked() ? "DM" : radDMS->isChecked() ? "DMS" : "D" ) );

// Announce that we may have a new display precision setting
emit displayPrecisionChanged();

@@ -609,7 +604,6 @@ void QgsProjectProperties::on_pbnCanvasColor_clicked()

void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged( int state )
{
btnGrpMapUnits->setEnabled( state == Qt::Unchecked );
projectionSelector->setEnabled( state == Qt::Checked );

if ( state != Qt::Checked )
@@ -632,23 +626,10 @@ void QgsProjectProperties::setMapUnitsToCurrentProjection()
QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
//set radio button to crs map unit type
QGis::UnitType units = srs.mapUnits();
switch ( units )
{
case QGis::Meters:
radMeters->setChecked( true );
break;
case QGis::Feet:
radFeet->setChecked( true );
break;
case QGis::Degrees:
radDecimalDegrees->setChecked( true );
break;
case QGis::DegreesMinutesSeconds:
radDMS->setChecked( true );
break;
default:
break;
}

radMeters->setChecked( units == QGis::Meters );
radFeet->setChecked( units == QGis::Feet );
radDegrees->setChecked( units == QGis::Degrees );
}
}

@@ -81,16 +81,19 @@ class CORE_EXPORT QGis

/** Map units that qgis supports
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
* @note and QGIS >1.8 returns to that
*/
enum UnitType
{
Meters = 0,
Feet = 1,
Degrees = 2, //for 1.0 api backwards compatibility
DecimalDegrees = 2,
DegreesMinutesSeconds = 4,
DegreesDecimalMinutes = 5,
UnknownUnit = 3
UnknownUnit = 3,

// for [1.4;1.8] api compatibility
DecimalDegrees = 2, // was 2
DegreesMinutesSeconds = 2, // was 4
DegreesDecimalMinutes = 2, // was 5
};

//! User defined event types
@@ -159,6 +159,25 @@ QString QgsPoint::toDegreesMinutesSeconds( int thePrecision ) const
return rep;
}

QString QgsPoint::toDegreesMinutes( int thePrecision ) const
{
int myDegreesX = int( qAbs( m_x ) );
float myFloatMinutesX = float(( qAbs( m_x ) - myDegreesX ) * 60 );

int myDegreesY = int( qAbs( m_y ) );
float myFloatMinutesY = float(( qAbs( m_y ) - myDegreesY ) * 60 );

QString myXHemisphere = m_x < 0 ? QObject::tr( "W" ) : QObject::tr( "E" );
QString myYHemisphere = m_y < 0 ? QObject::tr( "S" ) : QObject::tr( "N" );
QString rep = QString::number( myDegreesX ) + QChar( 176 ) +
QString::number( myFloatMinutesX, 'f', thePrecision ) + QString( "'" ) +
myXHemisphere + QString( "," ) +
QString::number( myDegreesY ) + QChar( 176 ) +
QString::number( myFloatMinutesY, 'f', thePrecision ) + QString( "'" ) +
myYHemisphere;
return rep;
}

QString QgsPoint::wellKnownText() const
{
return QString( "POINT(%1 %2)" ).arg( QString::number( m_x, 'f', 18 ) ).arg( QString::number( m_y, 'f', 18 ) );
@@ -133,6 +133,13 @@ class CORE_EXPORT QgsPoint
*/
QString toDegreesMinutesSeconds( int thePrecision ) const;

/** Return a string representation as degrees minutes.
* Its up to the calling function to ensure that this point can
* be meaningfully represented in this form.
* @note added in QGIS 1.9
*/
QString toDegreesMinutes( int thePrecision ) const;


/*! Return the well known text representation for the point.
* The wkt is created without an SRID.
@@ -66,24 +66,13 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
conversionFactor = 12.0;
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
break;
case QGis::DecimalDegrees:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
break;
case QGis::DegreesMinutesSeconds:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
break;
case QGis::DegreesDecimalMinutes:

default:
case QGis::Degrees:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
break;
default:
Q_ASSERT( "bad map units" );
break;
}
QgsDebugMsg( "Using conversionFactor of " + QString::number( conversionFactor ) );
if ( canvasWidth == 0 || mDpi == 0 )
@@ -96,7 +85,7 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
}


double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapExtent )
double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapExtent )
{
// need to calculate the x distance in meters
// We'll use the middle latitude for the calculation
@@ -2503,9 +2503,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
metersPerUnit = 0.3048;
break;

case QGis::DecimalDegrees:
case QGis::DegreesMinutesSeconds:
case QGis::DegreesDecimalMinutes:
case QGis::Degrees:
metersPerUnit = 111319.49079327358;
break;

@@ -3063,12 +3061,10 @@ bool QgsWmsProvider::calculateExtent()
}

QgsDebugMsg( "no extent returned" );

return false;
}
else
{

bool firstLayer = true; //flag to know if a layer is the first to be successfully transformed
for ( QStringList::Iterator it = mActiveSubLayers.begin();
it != mActiveSubLayers.end();
@@ -3115,10 +3111,6 @@ bool QgsWmsProvider::calculateExtent()
QgsDebugMsg( "exiting with '" + mLayerExtent.toString() + "'." );
return true;
}

QgsDebugMsg( "exiting without extent." );
return false;

}


0 comments on commit 93e0a43

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