Skip to content

Commit 0489c92

Browse files
author
g_j_m
committed
Warn the user if they are trying to measure lines or areas with qgis
thinking that the coord. system is geographic, but when the map extent is clearly showing a projected coord. system. Is an attempt to prevent more tickets like #301. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6291 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 94acb0a commit 0489c92

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/core/qgsdistancearea.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#define QGSDISTANCEAREA_H
1919

2020
#include <vector>
21+
#include "qgscoordinatetransform.h"
2122

22-
class QgsCoordinateTransform;
2323
class QgsGeometry;
2424

2525
/**
@@ -49,6 +49,8 @@ class QgsDistanceArea
4949
void setProjectAsSourceSRS();
5050
//! returns source spatial reference system
5151
long sourceSRS() { return mSourceRefSys; }
52+
//! What sort of coordinate system is being used?
53+
bool geographic() { return mCoordTransform->sourceSRS().geographicFlag(); }
5254

5355
//! sets ellipsoid by its acronym
5456
bool setEllipsoid(const QString& ellipsoid);

src/gui/qgsmeasure.cpp

+24-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsmaptopixel.h"
2424
#include "qgsrubberband.h"
2525

26+
#include "QMessageBox"
2627
#include <QSettings>
2728
#include <iostream>
2829

@@ -70,6 +71,29 @@ void QgsMeasure::activate()
7071
restorePosition();
7172
QgsMapTool::activate();
7273
mRightMouseClicked = false;
74+
75+
// ensure that we have correct settings
76+
mCalc->setDefaultEllipsoid();
77+
mCalc->setProjectAsSourceSRS();
78+
79+
// If we suspect that they have data that is projected, yet the
80+
// map SRS is set to a geographic one, warn them.
81+
if (mCalc->geographic() &&
82+
(mMapCanvas->extent().height() > 360 ||
83+
mMapCanvas->extent().width() > 720))
84+
{
85+
QMessageBox::warning(this, tr("Incorrect measure results"),
86+
tr("<p>This map is defined with a geographic coordinate system "
87+
"(latitude/longitude) "
88+
"but the map extents suggest that it is actually a projected "
89+
"coordinate system (e.g., Mercator). "
90+
"If so, the results from line or area measurements will be "
91+
"incorrect.</p>"
92+
"<p>To fix this, explicitly set an appropriate map coordinate "
93+
"system using the <tt>Settings:Project Properties</tt> menu."),
94+
QMessageBox::Ok,
95+
QMessageBox::NoButton);
96+
}
7397
}
7498

7599
void QgsMeasure::deactivate()
@@ -120,13 +144,6 @@ void QgsMeasure::addPoint(QgsPoint &point)
120144
QgsPoint pnt(point);
121145
mPoints.push_back(pnt);
122146

123-
if (mPoints.size() == 1)
124-
{
125-
// ensure that we have correct settings
126-
mCalc->setDefaultEllipsoid();
127-
mCalc->setProjectAsSourceSRS();
128-
}
129-
130147
if (mMeasureArea && mPoints.size() > 2)
131148
{
132149
double area = mCalc->measurePolygon(mPoints);

0 commit comments

Comments
 (0)