-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GDAL 3.0 Coordinate transformation (backwards compatibility (?)) #1546
Comments
The change is intended. |
Just to be clear, the if code needs to run with an arbitrary version of GDAL, you can do this: import osgeo
# ... so something to create and SRS:
srs = SpatialReference()
if int(osgeo.__version__[0]) >= 3:
# GDAL 3 changes axis order: https://github.com/OSGeo/gdal/issues/1546
srs.SetAxisMappingStrategy(osgeo.osr.OAMS_TRADITIONAL_GIS_ORDER) it would probably better to invert it the other way, eventually, and depend on |
The weird thing is if you use Transform on a geometry you get the same problem. I now have to reverse the X,Y in the Point geometry I create for the transformation to work. I can't imagine having to do this on polygon geometries, parsing out each point and reversing the X,Y to project it back correctly...
|
If you're wondering why phyghtmap 2.23 reverses coordinates, using latitude for longitude and viceversa, it's this issue. Until there's release with a fix for phyghtmap I have provided steps on how to install a patched version. Thanks @naught101 for the copy/paste ready fix. 😄 |
Expected behavior and actual behavior.
When using the Python bindings, the order of the input arguments for the
TransformPoint
method of aCoordinateTransformation
appears to be flipped compared to GDAL 2.4.I would expect the format to be:
x,y = ct.TransformPoint(x,y)
But GDAL 3.0 behaves like:
x,y = ct.TransformPoint(y,x)
Especially the mismatch between the input and output order is confusing.
I'm not completely sure this is a bug, since the migration guide mentions some changes with 'axis', but the new behavior seems very strange to me. I encountered this when debugging
geom.TransformTo
which caused my geometry to have flipped lat/lon.Steps to reproduce the problem.
With GDAL 3.0.0, the above code returns:
(inf, inf)
With GDAL 2.4.1, the above code returns:
(-13358338.89519283, 6446275.8410171615)
Using GDAL 3.0.0, but changing the input order to lat/lon returns:
mapx, mapy, z = ct_4326_to_3857.TransformPoint(lat, lon)
(-13358338.895192828, 6446275.841017158)
Both 3.0 and 2.4 show the expected behavior when using
gdaltransform.exe
from the command line, this is the output of 3.0:The docstring of
TransformPoint
changed a little bit from 2.4 to 3.0, but both docstrings suggest that the order of inputs should be (x,y,z).Some more comparisons (with varying x/y orders can be found in these notebooks:
GDAL 2.4:
https://nbviewer.jupyter.org/gist/RutgerK/75ee3016e58999b60469fd479655cf18
GDAL 3.0:
https://nbviewer.jupyter.org/gist/RutgerK/9c8d5255f566bafcb4bb543cc0f4eb7c
Since I've only used builds from conda, I can't rule out that it's related to the package/build process.
Operating system
Windows 10 (64bit)
GDAL version and provenance
GDAL 3.0.0 from conda-forge
Specifically:
https://conda.anaconda.org/conda-forge/win-64/libgdal-3.0.0-h47faea2_1.tar.bz2
https://conda.anaconda.org/conda-forge/win-64/gdal-3.0.0-py37hdf5ee75_1.tar.bz2
The text was updated successfully, but these errors were encountered: