Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added utility function toLayerCoords
git-svn-id: http://svn.osgeo.org/qgis/trunk@5192 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 6, 2006
1 parent 50ced72 commit 534abc8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/gui/qgsmaptool.cpp
Expand Up @@ -15,8 +15,10 @@
/* $Id$ */

#include "qgsmaptool.h"
#include "qgsmaplayer.h"
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsproject.h"
#include <QAction>

QgsMapTool::QgsMapTool(QgsMapCanvas* canvas)
Expand All @@ -36,6 +38,30 @@ QgsPoint QgsMapTool::toMapCoords(const QPoint& point)
}


QgsPoint QgsMapTool::toLayerCoords(QgsMapLayer* layer, const QPoint& point)
{
// FIXME: this information should be accessible elsewhere without accessing QgsProject!
bool projectionsEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

if (projectionsEnabled)
{

if (!layer || !layer->coordinateTransform())
return QgsPoint(0,0);

// first transform from canvas coords to map coordinates
QgsPoint pnt = toMapCoords(point);

// then convert from
return layer->coordinateTransform()->transform(pnt, QgsCoordinateTransform::INVERSE);
}
else
{
return toMapCoords(point);
}
}


QPoint QgsMapTool::toCanvasCoords(const QgsPoint& point)
{
double x = point.x(), y = point.y();
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmaptool.h
Expand Up @@ -20,6 +20,7 @@
#include <QCursor>
#include <QString>

class QgsMapLayer;
class QgsMapCanvas;
class QMouseEvent;
class QgsPoint;
Expand Down Expand Up @@ -74,6 +75,9 @@ class QgsMapTool
//! transformation from screen coordinates to map coordinates
QgsPoint toMapCoords(const QPoint& point);

//! transformation from screen coordinates to layer's coordinates
QgsPoint toLayerCoords(QgsMapLayer* layer, const QPoint& point);

//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoords(const QgsPoint& point);

Expand Down

0 comments on commit 534abc8

Please sign in to comment.