Skip to content

Commit 93e0a43

Browse files
committed
[FEATURE][API] allow display in degrees, decimal minutes
- store degree format setting in project file - [API] drop degree formats in unit type
1 parent 5a43d74 commit 93e0a43

File tree

10 files changed

+142
-104
lines changed

10 files changed

+142
-104
lines changed

python/core/qgis.sip

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ public:
7272

7373
/** Map units that qgis supports
7474
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
75+
* @note that QGIS > 1.8 api returns to that
7576
*/
7677
enum UnitType
7778
{
7879
Meters = 0,
7980
Feet = 1,
80-
Degrees = 2, //for 1.0 api backwards compatibility
81+
Degrees = 2,
82+
UnknownUnit = 3,
83+
84+
// for [1.4;1.8] api backwards compatibility
8185
DecimalDegrees = 2,
82-
DegreesMinutesSeconds = 4,
83-
DegreesDecimalMinutes = 5,
84-
UnknownUnit = 3
85-
} ;
86+
DegreesMinutesSeconds = 2,
87+
DegreesDecimalMinutes = 2,
88+
};
8689

8790
//! User defined event types
8891
enum UserEvent

src/app/qgisapp.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,14 +5025,22 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
50255025
}
50265026
else
50275027
{
5028-
if ( mMapCanvas->mapUnits() == QGis::DegreesMinutesSeconds )
5028+
if ( mMapCanvas->mapUnits() == QGis::Degrees )
50295029
{
5030-
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
5030+
QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );
5031+
5032+
if ( format == "DM" )
5033+
mCoordsEdit->setText( p.toDegreesMinutes( mMousePrecisionDecimalPlaces ) );
5034+
else if ( format == "DMS" )
5035+
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
5036+
else
5037+
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
50315038
}
50325039
else
50335040
{
50345041
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
50355042
}
5043+
50365044
if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
50375045
{
50385046
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );

src/app/qgsmeasuredialog.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ void QgsMeasureDialog::updateUi()
230230
case QGis::Feet:
231231
mTable->setHeaderLabels( QStringList( tr( "Segments (in feet)" ) ) );
232232
break;
233-
case QGis::DegreesMinutesSeconds:
234-
case QGis::DegreesDecimalMinutes:
235233
case QGis::Degrees:
236234
mTable->setHeaderLabels( QStringList( tr( "Segments (in degrees)" ) ) );
237235
break;

src/app/qgsprojectproperties.cpp

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
6969
//see if the user wants on the fly projection enabled
7070
bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled();
7171
cbxProjectionEnabled->setChecked( myProjectionEnabled );
72-
btnGrpMapUnits->setEnabled( !myProjectionEnabled );
7372

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

102+
QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );
103+
if ( format == "DM" )
104+
radDM->setChecked( true );
105+
else if ( format == "DMS" )
106+
radDMS->setChecked( true );
107+
else
108+
radD->setChecked( true );
109+
103110
//get the color selections and set the button color accordingly
104111
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
105112
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
@@ -328,22 +335,11 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
328335
{
329336
unit = QGis::Meters;
330337
}
331-
if ( unit == QGis::Meters )
332-
{
333-
radMeters->setChecked( true );
334-
}
335-
else if ( unit == QGis::Feet )
336-
{
337-
radFeet->setChecked( true );
338-
}
339-
else if ( unit == QGis::DegreesMinutesSeconds )
340-
{
341-
radDMS->setChecked( true );
342-
}
343-
else
344-
{
345-
radDecimalDegrees->setChecked( true );
346-
}
338+
339+
radMeters->setChecked( unit == QGis::Meters );
340+
radFeet->setChecked( unit == QGis::Feet );
341+
radDegrees->setChecked( unit == QGis::Degrees );
342+
347343
mMapCanvas->mapRenderer()->setMapUnits( unit );
348344
}
349345

@@ -369,21 +365,17 @@ void QgsProjectProperties::apply()
369365
// Note. Qt 3.2.3 and greater have a function selectedId() that
370366
// can be used instead of the two part technique here
371367
QGis::UnitType mapUnit;
372-
if ( radMeters->isChecked() )
368+
if ( radDegrees->isChecked() )
373369
{
374-
mapUnit = QGis::Meters;
370+
mapUnit = QGis::Degrees;
375371
}
376372
else if ( radFeet->isChecked() )
377373
{
378374
mapUnit = QGis::Feet;
379375
}
380-
else if ( radDMS->isChecked() )
381-
{
382-
mapUnit = QGis::DegreesMinutesSeconds;
383-
}
384376
else
385377
{
386-
mapUnit = QGis::Degrees;
378+
mapUnit = QGis::Meters;
387379
}
388380

389381
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
@@ -423,6 +415,9 @@ void QgsProjectProperties::apply()
423415
// can be used instead of the two part technique here
424416
QgsProject::instance()->writeEntry( "PositionPrecision", "/Automatic", radAutomatic->isChecked() );
425417
QgsProject::instance()->writeEntry( "PositionPrecision", "/DecimalPlaces", spinBoxDP->value() );
418+
QgsProject::instance()->writeEntry( "PositionPrecision", "/DegreeFormat",
419+
QString( radDM->isChecked() ? "DM" : radDMS->isChecked() ? "DMS" : "D" ) );
420+
426421
// Announce that we may have a new display precision setting
427422
emit displayPrecisionChanged();
428423

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

610605
void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged( int state )
611606
{
612-
btnGrpMapUnits->setEnabled( state == Qt::Unchecked );
613607
projectionSelector->setEnabled( state == Qt::Checked );
614608

615609
if ( state != Qt::Checked )
@@ -632,23 +626,10 @@ void QgsProjectProperties::setMapUnitsToCurrentProjection()
632626
QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
633627
//set radio button to crs map unit type
634628
QGis::UnitType units = srs.mapUnits();
635-
switch ( units )
636-
{
637-
case QGis::Meters:
638-
radMeters->setChecked( true );
639-
break;
640-
case QGis::Feet:
641-
radFeet->setChecked( true );
642-
break;
643-
case QGis::Degrees:
644-
radDecimalDegrees->setChecked( true );
645-
break;
646-
case QGis::DegreesMinutesSeconds:
647-
radDMS->setChecked( true );
648-
break;
649-
default:
650-
break;
651-
}
629+
630+
radMeters->setChecked( units == QGis::Meters );
631+
radFeet->setChecked( units == QGis::Feet );
632+
radDegrees->setChecked( units == QGis::Degrees );
652633
}
653634
}
654635

src/core/qgis.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,19 @@ class CORE_EXPORT QGis
8181

8282
/** Map units that qgis supports
8383
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
84+
* @note and QGIS >1.8 returns to that
8485
*/
8586
enum UnitType
8687
{
8788
Meters = 0,
8889
Feet = 1,
8990
Degrees = 2, //for 1.0 api backwards compatibility
90-
DecimalDegrees = 2,
91-
DegreesMinutesSeconds = 4,
92-
DegreesDecimalMinutes = 5,
93-
UnknownUnit = 3
91+
UnknownUnit = 3,
92+
93+
// for [1.4;1.8] api compatibility
94+
DecimalDegrees = 2, // was 2
95+
DegreesMinutesSeconds = 2, // was 4
96+
DegreesDecimalMinutes = 2, // was 5
9497
};
9598

9699
//! User defined event types

src/core/qgspoint.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ QString QgsPoint::toDegreesMinutesSeconds( int thePrecision ) const
159159
return rep;
160160
}
161161

162+
QString QgsPoint::toDegreesMinutes( int thePrecision ) const
163+
{
164+
int myDegreesX = int( qAbs( m_x ) );
165+
float myFloatMinutesX = float(( qAbs( m_x ) - myDegreesX ) * 60 );
166+
167+
int myDegreesY = int( qAbs( m_y ) );
168+
float myFloatMinutesY = float(( qAbs( m_y ) - myDegreesY ) * 60 );
169+
170+
QString myXHemisphere = m_x < 0 ? QObject::tr( "W" ) : QObject::tr( "E" );
171+
QString myYHemisphere = m_y < 0 ? QObject::tr( "S" ) : QObject::tr( "N" );
172+
QString rep = QString::number( myDegreesX ) + QChar( 176 ) +
173+
QString::number( myFloatMinutesX, 'f', thePrecision ) + QString( "'" ) +
174+
myXHemisphere + QString( "," ) +
175+
QString::number( myDegreesY ) + QChar( 176 ) +
176+
QString::number( myFloatMinutesY, 'f', thePrecision ) + QString( "'" ) +
177+
myYHemisphere;
178+
return rep;
179+
}
180+
162181
QString QgsPoint::wellKnownText() const
163182
{
164183
return QString( "POINT(%1 %2)" ).arg( QString::number( m_x, 'f', 18 ) ).arg( QString::number( m_y, 'f', 18 ) );

src/core/qgspoint.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class CORE_EXPORT QgsPoint
133133
*/
134134
QString toDegreesMinutesSeconds( int thePrecision ) const;
135135

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

137144
/*! Return the well known text representation for the point.
138145
* The wkt is created without an SRID.

src/core/qgsscalecalculator.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,13 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
6666
conversionFactor = 12.0;
6767
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
6868
break;
69-
case QGis::DecimalDegrees:
70-
// degrees require conversion to meters first
71-
conversionFactor = 39.3700787;
72-
delta = calculateGeographicDistance( mapExtent );
73-
break;
74-
case QGis::DegreesMinutesSeconds:
75-
// degrees require conversion to meters first
76-
conversionFactor = 39.3700787;
77-
delta = calculateGeographicDistance( mapExtent );
78-
break;
79-
case QGis::DegreesDecimalMinutes:
69+
70+
default:
71+
case QGis::Degrees:
8072
// degrees require conversion to meters first
8173
conversionFactor = 39.3700787;
8274
delta = calculateGeographicDistance( mapExtent );
8375
break;
84-
default:
85-
Q_ASSERT( "bad map units" );
86-
break;
8776
}
8877
QgsDebugMsg( "Using conversionFactor of " + QString::number( conversionFactor ) );
8978
if ( canvasWidth == 0 || mDpi == 0 )
@@ -96,7 +85,7 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
9685
}
9786

9887

99-
double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapExtent )
88+
double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapExtent )
10089
{
10190
// need to calculate the x distance in meters
10291
// We'll use the middle latitude for the calculation

src/providers/wms/qgswmsprovider.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,9 +2503,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
25032503
metersPerUnit = 0.3048;
25042504
break;
25052505

2506-
case QGis::DecimalDegrees:
2507-
case QGis::DegreesMinutesSeconds:
2508-
case QGis::DegreesDecimalMinutes:
2506+
case QGis::Degrees:
25092507
metersPerUnit = 111319.49079327358;
25102508
break;
25112509

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

30653063
QgsDebugMsg( "no extent returned" );
3066-
30673064
return false;
30683065
}
30693066
else
30703067
{
3071-
30723068
bool firstLayer = true; //flag to know if a layer is the first to be successfully transformed
30733069
for ( QStringList::Iterator it = mActiveSubLayers.begin();
30743070
it != mActiveSubLayers.end();
@@ -3115,10 +3111,6 @@ bool QgsWmsProvider::calculateExtent()
31153111
QgsDebugMsg( "exiting with '" + mLayerExtent.toString() + "'." );
31163112
return true;
31173113
}
3118-
3119-
QgsDebugMsg( "exiting without extent." );
3120-
return false;
3121-
31223114
}
31233115

31243116

0 commit comments

Comments
 (0)