[Qgis-developer] Getting center of layer in lat/long

Leyan ouyang.leyan.ml at hotmail.com
Wed Sep 10 04:05:50 PDT 2014


On 09/09/2014 05:36 AM, Mark Coletti wrote:
>         layerCenter = layer.extent().center()
>
>         if layer.crs().geographicFlag() : # if already lat/long, do 
> nothing
>             return layerCenter
>         else :
>             sourceCRC = layer.crs() # get the coordinate reference 
> system being used
>             # 4326 is WGS 84
>             coordinateTransform = 
> QgsCoordinateTransform(sourceCRC.toWkt(), 
> QgsCoordinateReferenceSystem(4326).toWkt())
>             return coordinateTransform.transform(layerCenter)
>
If you want to be rigorous, there are different lat/long coordinate 
system, it is not only WGS84. The difference will be small of course, 
but I do not see the point of specifically testing for this case while 
it does not add anything.

Regards,

Leyan


More information about the Qgis-developer mailing list