I failed to transform two different Geodetic CRS

from pyproj import Proj, transform

#Transform from Arc1950 to WGS84
inProj = Proj(init='epsg:4326')
outProj = Proj(init='epsg:4209')
x1,y1 = 27.04892, -13.30552
x2,y2 = transform(inProj,outProj,x1,y1)
print x2,y2

but the return:

27.04892 -13.30552

this is not a correct result, it should be 27.04906, -13.30400.(I got this correct result from Mapsource.)

  • If you have access to QGIS, you can do transformation using PyQGIS which gives you the correct results. – Joseph Oct 5 '16 at 10:19
  • thanks a lot, I will try PyQGIS. is there any module i can do as this? – udbird Oct 7 '16 at 10:01
  • I've added a post to describe how you could use it =) – Joseph Oct 7 '16 at 11:05

If you want to use QGIS, you can use the following code in the Python Console which uses the QgsCoordinateReferenceSystem class to transform your points:

old_crs = QgsCoordinateReferenceSystem(4326)
new_crs = QgsCoordinateReferenceSystem(4209)
transform = QgsCoordinateTransform(old_crs, new_crs)
transform_points = transform.transform(QgsPoint(27.04892, -13.30552))
print transform_points

This will print out:



If you want to use this outside QGIS such as in the OSGeo4W shell then you could use the osgeo.osr.SpatialReference() class:

from osgeo import osr 
old_crs = osr.SpatialReference() 
new_crs = osr.SpatialReference() 
transform = osr.CoordinateTransformation(old_crs,new_crs) 
transform_points = transform.TransformPoint(27.04892, -13.30552)
print transform_points[0], transform_points[1] 

This should print out:

27.0490596011 -13.3039944497

Standalone image

| improve this answer | |
  • thanks for your code, but i still failed to get the correct result, i couldn't post the capture here, i upload the capture to my google photo, goo.gl/photos/xmNGKJ9jWWrPyNwk7 – udbird Oct 7 '16 at 13:02
  • @udbird - Good point, edited post to show another method :) – Joseph Oct 7 '16 at 13:19
  • it is weird, i run these codes using ipython shell in ubuntu 12.04, and failed again. Maybe there are some bugs with my linux, i will try the codes after i install osgeo module windows version. thanks for your helps. goo.gl/photos/xmNGKJ9jWWrPyNwk7 – udbird Oct 7 '16 at 13:40
  • @udbird - Yes that is weird, hope you get the results when you install the windows version! – Joseph Oct 7 '16 at 13:44
  • It works with windows version in my computer. thank u! – udbird Oct 7 '16 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.