Skip to content
Permalink
Browse files

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@6291 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Dec 20, 2006
1 parent bb63c62 commit b483e29c9bed876e6e4fdf229b08321786102a0a
Showing with 27 additions and 8 deletions.
  1. +3 −1 src/core/qgsdistancearea.h
  2. +24 −7 src/gui/qgsmeasure.cpp
@@ -18,8 +18,8 @@
#define QGSDISTANCEAREA_H

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

class QgsCoordinateTransform;
class QgsGeometry;

/**
@@ -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);
@@ -23,6 +23,7 @@
#include "qgsmaptopixel.h"
#include "qgsrubberband.h"

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

@@ -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()
@@ -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);

0 comments on commit b483e29

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