[Qgis-user] Issues with QgsCoordinateTransform

Tudorache, Marian Marian.Tudorache at navcanada.ca
Wed Sep 9 11:32:34 PDT 2015


Hi everyone,

I have this script and run on python console of QGIS 2.8
######################################################
import processing, sys, os, math, LatLon, pyproj
from PyQt4 import QtCore
crsScr  = QgsCoordinateReferenceSystem(100006, QgsCoordinateReferenceSystem.InternalCrsId)
crsDest = QgsCoordinateReferenceSystem(100000, QgsCoordinateReferenceSystem.InternalCrsId)
xform = QgsCoordinateTransform(crsScr, crsDest)

coord_start = '53 30 21.88 N, 114 25 15.88 W'
coord_end = '54 40 21.88 N, 115 30 15.88 W'
start_Point = coord_start.split(',')
end_Point = coord_end.split(',')
#print "'"+str(start_Point[0]).strip()+"'", "'"+str(start_Point[1]).strip()+"'"

#start_Line = LatLon.string2latlon('53 30 21.88 N', '115 25 15.88 W', 'd% %m% %S% %H')
#print start_Line
start_Line = LatLon.string2latlon(str(start_Point[0]).strip(), str(start_Point[1]).strip(), 'd% %m% %S% %H')
end_Line = LatLon.string2latlon(str(end_Point[0]).strip(), str(end_Point[1]).strip(), 'd% %m% %S% %H')
print "QgsPoint = ",QgsPoint(float(start_Line.to_string()[0]), float(start_Line.to_string()[1]))


line_start = QgsPoint(float(start_Line.to_string()[0]), float(start_Line.to_string()[1]))
line_end = QgsPoint(float(end_Line.to_string()[0]), float(end_Line.to_string()[1]))
pointGeomStart = QgsGeometry.fromPoint(line_start)
pointGeomEnd = QgsGeometry.fromPoint(line_end)
print "Geometry points Start = {0}, End = {1}".format(pointGeomStart.asPoint(), pointGeomEnd.asPoint())
print "QgsCoordinateTransform.ReverseTransform = ",xform.transform(pointGeomStart.asPoint(), QgsCoordinateTransform.ReverseTransform)
print "QgsCoordinateTransform.ForwardTransform = ",xform.transform(pointGeomStart.asPoint(), QgsCoordinateTransform.ForwardTransform)
#####################################################################################################

The InternalCrsIdfor=100006 is: +proj=longlat +datum=GRS80 +no_defs
The InternalCrsIdfor=100000 is: +proj=sterea +lat_0=53.5 +lon_0=-76.0 +k=1 +x_0=0 +y_0=0 +a=6381816.160744 +b=6381816.160744 +units=m +no_defs

I try to transform the coordinate '53 30 21.88 N, 114 25 15.88 W' and '54 40 21.88 N, 115 30 15.88 W' from 100006 to 100000

This is the output
QgsPoint =  (53.5061,-114.421)
Geometry points Start = (53.5061,-114.421), End = (54.6727,-115.504)
QgsCoordinateTransform.ReverseTransform =  (53.5061,-114.421)
QgsCoordinateTransform.ForwardTransform =  (53.5061,-114.421)


Basically there is no diference between ReverseTransform and ForwardTransform. I am expecting to get X=-2549670.6 and Y=678.9 or (-2549670.6,678.9) when I am doing forward transformation.


Any idea what is wrong?

Thanks,
Marian

This electronic message, as well as any transmitted files included in the electronic message, may contain privileged or confidential information and is intended solely for the use of the individual(s) or entity to which it is addressed. If you have received this electronic message in error please notify the sender immediately and delete the electronic message. Any unauthorized copying, disclosure or distribution of the electronic message is strictly forbidden. NAV CANADA accepts no liability for any damage caused by any virus and/or other malicious code transmitted by this electronic communication.

Le présent message électronique et tout fichier qui peut y être joint peuvent contenir des renseignements privilégiés ou confidentiels destinés à l’usage exclusif des personnes ou des organismes à qui ils s’adressent. Si vous avez reçu ce message électronique par erreur, veuillez en informer l’expéditeur immédiatement et supprimez le. Toute reproduction, divulgation ou distribution du présent message électronique est strictement interdite. NAV CANADA n’assume aucune responsabilité en cas de dommage causé par tout virus ou autre programme malveillant transmis par ce message électronique.


More information about the Qgis-user mailing list