Skip to content
Permalink
Browse files

A quick hack to investigate measurements when projection is off.

Feedback welcome!


git-svn-id: http://svn.osgeo.org/qgis/trunk@6446 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Jan 20, 2007
1 parent 1a661ae commit 51087d3a15889eaa9d6ab4700df97afcc607f39e
Showing with 94 additions and 26 deletions.
  1. +76 −23 src/app/qgsmeasure.cpp
  2. +1 −1 src/app/qgsmeasure.h
  3. +5 −1 src/core/qgsdistancearea.cpp
  4. +7 −1 src/core/qgsmaprender.cpp
  5. +5 −0 src/core/qgsmaprender.h
@@ -52,7 +52,7 @@ QgsMeasure::QgsMeasure(bool measureArea, QgsMapCanvas *mc, Qt::WFlags f)
mTable->setNumRows(1);
mTable->setText(0, 0, QString::number(0, 'f',1));

mTable->horizontalHeader()->setLabel( 0, tr("Segments (in meters)") );
//mTable->horizontalHeader()->setLabel( 0, tr("Segments (in meters)") );
//mTable->horizontalHeader()->setLabel( 1, tr("Total") );
//mTable->horizontalHeader()->setLabel( 2, tr("Azimuth") );

@@ -64,7 +64,7 @@ QgsMeasure::QgsMeasure(bool measureArea, QgsMapCanvas *mc, Qt::WFlags f)

connect( mMapCanvas, SIGNAL(renderComplete(QPainter*)), this, SLOT(mapCanvasChanged()) );

mCalc = new QgsDistanceArea;
//mCalc = new QgsDistanceArea;

mRubberBand = new QgsRubberBand(mMapCanvas, mMeasureArea);

@@ -84,7 +84,7 @@ void QgsMeasure::activate()

// 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() &&
if (mCanvas->mapRender()->distArea()->geographic() &&
(mMapCanvas->extent().height() > 360 ||
mMapCanvas->extent().width() > 720))
{
@@ -119,7 +119,7 @@ void QgsMeasure::setMeasureArea(bool measureArea)

QgsMeasure::~QgsMeasure()
{
delete mCalc;
// delete mCalc;
delete mRubberBand;
}

@@ -169,7 +169,7 @@ void QgsMeasure::addPoint(QgsPoint &point)

if (mMeasureArea && mPoints.size() > 2)
{
double area = mCalc->measurePolygon(mPoints);
double area = mCanvas->mapRender()->distArea()->measurePolygon(mPoints);
editTotal->setText(formatArea(area));
}
else if (!mMeasureArea && mPoints.size() > 1)
@@ -178,7 +178,7 @@ void QgsMeasure::addPoint(QgsPoint &point)

QgsPoint p1 = mPoints[last], p2 = mPoints[last+1];

double d = mCalc->measureLine(p1,p2);
double d = mCanvas->mapRender()->distArea()->measureLine(p1,p2);

mTotal += d;
editTotal->setText(formatDistance(mTotal));
@@ -223,15 +223,15 @@ void QgsMeasure::mouseMove(QgsPoint &point)
tmpPoints.push_back(point);
if (mMeasureArea && tmpPoints.size() > 2)
{
double area = mCalc->measurePolygon(tmpPoints);
double area = mCanvas->mapRender()->distArea()->measurePolygon(tmpPoints);
editTotal->setText(formatArea(area));
}
else if (!mMeasureArea && tmpPoints.size() > 1)
{
int last = tmpPoints.size()-2;
QgsPoint p1 = tmpPoints[last], p2 = tmpPoints[last+1];

double d = mCalc->measureLine(p1,p2);
double d = mCanvas->mapRender()->distArea()->measureLine(p1,p2);
mTable->setText(last, 0, QString::number(d, 'f',1));
editTotal->setText(formatDistance(mTotal + d));
}
@@ -296,16 +296,52 @@ void QgsMeasure::on_btnHelp_clicked()
QString QgsMeasure::formatDistance(double distance)
{
QString txt;
if (distance < 1000)
{
txt = QString::number(distance,'f',0);
txt += " m";
}
else
QString unitLabel;

QGis::units myMapUnits = mCanvas->mapUnits();
switch (myMapUnits)
{
txt = QString::number(distance/1000,'f',1);
txt += " km";
}
case QGis::METERS:
if (distance > 1000.0)
{
unitLabel=tr(" km");
distance = distance/1000;
}
else if (distance < 0.01)
{
unitLabel=tr(" mm");
distance = distance*1000;
}
else if (distance < 0.1)
{
unitLabel=tr(" cm");
distance = distance*100;
}
else
unitLabel=tr(" m");
break;
case QGis::FEET:
if (distance == 1.0)
unitLabel=tr(" foot");
else
unitLabel=tr(" feet");
break;
case QGis::DEGREES:
if (distance == 1.0)
unitLabel=tr(" degree");
else
unitLabel=tr(" degrees");
break;
case QGis::UNKNOWN:
unitLabel=tr(" unknown");
default:
std::cout << "Error: not picked up map units - actual value = "
<< myMapUnits << std::endl;
};

txt = QString::number(distance,'f',1);
txt += unitLabel;

return txt;
}

@@ -327,6 +363,23 @@ QString QgsMeasure::formatArea(double area)

void QgsMeasure::updateUi()
{

QGis::units myMapUnits = mCanvas->mapUnits();
switch (myMapUnits)
{
case QGis::METERS:
mTable->horizontalHeader()->setLabel( 0, tr("Segments (in meters)") );
break;
case QGis::FEET:
mTable->horizontalHeader()->setLabel( 0, tr("Segments (in feet)") );
break;
case QGis::DEGREES:
mTable->horizontalHeader()->setLabel( 0, tr("Segments (in degrees)") );
break;
case QGis::UNKNOWN:
mTable->horizontalHeader()->setLabel( 0, tr("Segments") );
};

if (mMeasureArea)
{
mTable->hide();
@@ -344,14 +397,14 @@ void QgsMeasure::updateProjection()
{
// set ellipsoid
QSettings settings;
QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
mCalc->setEllipsoid(ellipsoid);
// QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
// mCalc->setEllipsoid(ellipsoid);

// set source SRS and projections enabled flag
QgsMapRender* mapRender = mCanvas->mapRender();
mCalc->setProjectionsEnabled(mapRender->projectionsEnabled());
int srsid = mapRender->destinationSrs().srsid();
mCalc->setSourceSRS(srsid);
// QgsMapRender* mapRender = mCanvas->mapRender();
// mCalc->setProjectionsEnabled(mapRender->projectionsEnabled());
// int srsid = mapRender->destinationSrs().srsid();
// mCalc->setSourceSRS(srsid);

int myRed = settings.value("/qgis/default_measure_color_red", 180).toInt();
int myGreen = settings.value("/qgis/default_measure_color_green", 180).toInt();
@@ -111,7 +111,7 @@ public slots:
QgsMapCanvas *mMapCanvas;

//! distance/area calculator
QgsDistanceArea* mCalc;
//QgsDistanceArea* mCalc;

std::vector<QgsPoint> mPoints;

@@ -279,8 +279,12 @@ double QgsDistanceArea::measureLine(const QgsPoint& p1, const QgsPoint& p2)
{
pp1 = mCoordTransform->transform(p1);
pp2 = mCoordTransform->transform(p2);
return computeDistanceBearing(pp1, pp2);
}
else
{
return sqrt((p2.x()-p1.x())*(p2.x()-p1.x()) + (p2.y()-p1.y())*(p2.y()-p1.y()));
}
return computeDistanceBearing(pp1, pp2);
}
catch (QgsCsException &cse)
{
@@ -24,6 +24,7 @@
#include "qgsmaptopixel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsdistancearea.h"
//#include "qgsspatialrefsys.h"

#include <QDomDocument>
@@ -37,6 +38,7 @@ QgsMapRender::QgsMapRender()
{
mCoordXForm = new QgsMapToPixel;
mScaleCalculator = new QgsScaleCalculator;
mDistArea = new QgsDistanceArea;

mDrawing = false;
mOverview = false;
@@ -55,6 +57,7 @@ QgsMapRender::~QgsMapRender()
{
delete mCoordXForm;
delete mScaleCalculator;
delete mDistArea;
delete mDestSRS;
}

@@ -365,6 +368,8 @@ void QgsMapRender::setProjectionsEnabled(bool enabled)
if (mProjectionsEnabled != enabled)
{
mProjectionsEnabled = enabled;
QgsDebugMsg("Adjusting DistArea projection on/off");
mDistArea->setProjectionsEnabled(enabled);
updateFullExtent();
emit projectionsEnabled(enabled);
}
@@ -382,7 +387,8 @@ void QgsMapRender::setDestinationSrs(const QgsSpatialRefSys& srs)
QgsDebugMsg("* DestSRS.proj4() = " + srs.proj4String());
if (*mDestSRS != srs)
{
QgsDebugMsg("No, changed my mind!");
QgsDebugMsg("Setting DistArea SRS to " + QString::number(srs.srsid()));
mDistArea->setSourceSRS(srs.srsid());
*mDestSRS = srs;
updateFullExtent();
emit destinationSrsChanged();
@@ -32,6 +32,7 @@ class QgsMapToPixel;
class QgsMapLayer;
class QgsScaleCalculator;
class QgsSpatialRefSys;
class QgsDistanceArea;

/**
* \class QgsMapRender
@@ -68,6 +69,8 @@ class CORE_EXPORT QgsMapRender : public QObject
//! Recalculate the map scale
void updateScale();

//! Return the measuring object
QgsDistanceArea* distArea() { return mDistArea; }
QGis::units mapUnits() const;
void setMapUnits(QGis::units u);

@@ -191,6 +194,8 @@ class CORE_EXPORT QgsMapRender : public QObject
//! full extent of the layer set
QgsRect mFullExtent;

//! tool for measuring
QgsDistanceArea* mDistArea;
};

#endif

0 comments on commit 51087d3

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