Skip to content

Commit

Permalink
Added utility function toLayerCoords
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5192 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 6, 2006
1 parent 596f4ae commit 8e7f09c
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8e7f09c

Please sign in to comment.