Skip to content

Commit

Permalink
Warn the user if they are trying to measure lines or areas with qgis
Browse files Browse the repository at this point in the history
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
  • Loading branch information
g_j_m committed Dec 20, 2006
1 parent 94acb0a commit 0489c92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/core/qgsdistancearea.h
Expand Up @@ -18,8 +18,8 @@
#define QGSDISTANCEAREA_H

#include <vector>
#include "qgscoordinatetransform.h"

class QgsCoordinateTransform;
class QgsGeometry;

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

//! sets ellipsoid by its acronym
bool setEllipsoid(const QString& ellipsoid);
Expand Down
31 changes: 24 additions & 7 deletions src/gui/qgsmeasure.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgsmaptopixel.h"
#include "qgsrubberband.h"

#include "QMessageBox"
#include <QSettings>
#include <iostream>

Expand Down Expand Up @@ -70,6 +71,29 @@ void QgsMeasure::activate()
restorePosition();
QgsMapTool::activate();
mRightMouseClicked = false;

// ensure that we have correct settings
mCalc->setDefaultEllipsoid();
mCalc->setProjectAsSourceSRS();

// If we suspect that they have data that is projected, yet the
// map SRS is set to a geographic one, warn them.
if (mCalc->geographic() &&
(mMapCanvas->extent().height() > 360 ||
mMapCanvas->extent().width() > 720))
{
QMessageBox::warning(this, tr("Incorrect measure results"),
tr("<p>This map is defined with a geographic coordinate system "
"(latitude/longitude) "
"but the map extents suggest that it is actually a projected "
"coordinate system (e.g., Mercator). "
"If so, the results from line or area measurements will be "
"incorrect.</p>"
"<p>To fix this, explicitly set an appropriate map coordinate "
"system using the <tt>Settings:Project Properties</tt> menu."),
QMessageBox::Ok,
QMessageBox::NoButton);
}
}

void QgsMeasure::deactivate()
Expand Down Expand Up @@ -120,13 +144,6 @@ void QgsMeasure::addPoint(QgsPoint &point)
QgsPoint pnt(point);
mPoints.push_back(pnt);

if (mPoints.size() == 1)
{
// ensure that we have correct settings
mCalc->setDefaultEllipsoid();
mCalc->setProjectAsSourceSRS();
}

if (mMeasureArea && mPoints.size() > 2)
{
double area = mCalc->measurePolygon(mPoints);
Expand Down

0 comments on commit 0489c92

Please sign in to comment.