2

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.)

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
udbird
  • 23
  • 2

1 Answers1

0

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:

(27.0491,-13.304)

Image


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() 
old_crs.ImportFromEPSG(4326) 
new_crs = osr.SpatialReference() 
new_crs.ImportFromEPSG(4209) 
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

Joseph
  • 75,746
  • 7
  • 171
  • 282
  • 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, https://goo.gl/photos/xmNGKJ9jWWrPyNwk7 – udbird Oct 07 '16 at 13:02
  • @udbird - Good point, edited post to show another method :) – Joseph Oct 07 '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. https://goo.gl/photos/xmNGKJ9jWWrPyNwk7 – udbird Oct 07 '16 at 13:40
  • @udbird - Yes that is weird, hope you get the results when you install the windows version! – Joseph Oct 07 '16 at 13:44
  • It works with windows version in my computer. thank u! – udbird Oct 07 '16 at 17:59
  • The osgeo module works with 2.7.6 version in ubuntu 14.04, but qgis failed. – udbird Oct 07 '16 at 19:11
  • @udbird - Glad it works (on Windows atleast)! Can't confirm the same issue for Ubuntu as I do not use it :) – Joseph Oct 10 '16 at 09:38