[Qgis-developer] Getting WGS84 for a point
Martin Dobias
wonder.sk at gmail.com
Wed May 5 05:29:20 EDT 2010
Hi Barry
On Sun, May 2, 2010 at 9:01 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> However if I start a new project and load in a shapefile with, say, an
> OSGB CRS set in it's .prj file, my code doesn't do anything special,
> doesn't find a project CRS, and so sends google maps a query with
> lat=4453500 and lng=6755300.
>
> Perhaps my code should check if the current layer has a CRS and
> transform to WGS84 based on that instead of testing for a project CRS?
> Or should it do both? Which first? Or am I doing something wrong here?
I would use QgsMapTool.toLayerCoordinates() method to find out the
clicked point's coordinates in the CRS of the layer. Then I would
transform it to WGS84 using QgsCoordinateTransform class.
The toLayerCoordinates() method first converts the point from canvas
widget coordinates to map (project) coordinates. Then, if the
on-the-fly projections are turned on, the map coordinates are further
transformed to layer coordinates. You don't have to work with project
CRS.
Cheers
Martin
More information about the Qgis-developer
mailing list