import gdal
import osr
gdal.UseExceptions()
gdal.VersionInfo()
'3000000'
srs_4326 = osr.SpatialReference()
srs_4326.ImportFromEPSG(4326)
0
srs_3857 = osr.SpatialReference()
srs_3857.ImportFromEPSG(3857)
0
ct_3857_to_4326 = osr.CoordinateTransformation(srs_3857, srs_4326)
ct_4326_to_3857 = osr.CoordinateTransformation(srs_4326, srs_3857)
lat = 50.0
lon = -120.0
# Incorrect output, and different compared to GDAL 2.4
mapx, mapy, z = ct_4326_to_3857.TransformPoint(lon, lat)
mapx, mapy
(inf, inf)
lat = 50.0
lon = -120.0
# this output is equivalent to the cmd (gdaltransform.exe) (but (x,y) -> (y,x))
mapx, mapy, z = ct_4326_to_3857.TransformPoint(lat, lon)
mapx, mapy
(-13358338.895192828, 6446275.841017158)
mapx = -13358338.895192828
mapy = 6446275.841017158
# Wrong output order (?), but correct values # (x,y) -> (y,x)
ct_3857_to_4326.TransformPoint(mapx, mapy)
(49.99999999999999, -119.99999999999999, 0.0)
mapx = -13358338.895192828
mapy = 6446275.841017158
# Incorrect results
ct_3857_to_4326.TransformPoint(mapy, mapx)
(-75.95934455387825, 57.90788113636135, 0.0)
# (py37) C:\Users\Rutger>gdaltransform --version
# GDAL 3.0.0, released 2019/05/05
# (py37) C:\Users\Rutger>gdaltransform -s_srs EPSG:4326 -t_srs EPSG:3857
# -120 50
# -13358338.8951928 6446275.84101716 0
# docstring suggests (x,y,z)
ct_4326_to_3857.TransformPoint?
Signature: ct_4326_to_3857.TransformPoint(*args) Docstring: TransformPoint(CoordinateTransformation self, double [3] inout) TransformPoint(CoordinateTransformation self, double [4] inout) TransformPoint(CoordinateTransformation self, double x, double y, double z=0.0) TransformPoint(CoordinateTransformation self, double x, double y, double z, double t) File: c:\miniconda3\envs\py37\lib\site-packages\osgeo\osr.py Type: method