diff --git a/autotest/osr/osr_ct.py b/autotest/osr/osr_ct.py index e8b2f62d3711..ec4ab4b2dd48 100755 --- a/autotest/osr/osr_ct.py +++ b/autotest/osr/osr_ct.py @@ -90,6 +90,21 @@ def test_osr_ct_2(): and result[2] == pytest.approx(0.0, abs=0.01) ), "Wrong LL to UTM result" + result = ct.TransformPoint([32.0, -117.5, 10.0]) + assert ( + result[0] == pytest.approx(452772.06, abs=0.01) + and result[1] == pytest.approx(3540544.89, abs=0.01) + and result[2] == 10 + ), "Wrong LL to UTM result" + + result = ct.TransformPoint([32.0, -117.5, 10.0, 2000.0]) + assert ( + result[0] == pytest.approx(452772.06, abs=0.01) + and result[1] == pytest.approx(3540544.89, abs=0.01) + and result[2] == 10 + and result[3] == 2000 + ), "Wrong LL to UTM result" + ############################################################################### # Transform an OGR geometry ... this is mostly aimed at ensuring that diff --git a/swig/include/ogr.i b/swig/include/ogr.i index ba48e705df6d..3f582d744b4e 100644 --- a/swig/include/ogr.i +++ b/swig/include/ogr.i @@ -619,7 +619,6 @@ typedef int OGRErr; %{ #include "gdal.h" %} -typedef int CPLErr; #define FROM_PYTHON_OGR_I %include MajorObject.i #undef FROM_PYTHON_OGR_I diff --git a/swig/include/osr.i b/swig/include/osr.i index 714db177c4d2..8ae1900839b9 100644 --- a/swig/include/osr.i +++ b/swig/include/osr.i @@ -1237,7 +1237,11 @@ public: %apply (double argout[ANY]) {(double inout[3])}; %apply (double argin[ANY]) {(double inout[3])}; #endif +#if SWIGPYTHON + void _TransformPoint3Double( double inout[3] ) { +#else void TransformPoint( double inout[3] ) { +#endif if (self == NULL) return; OCTTransform( self, 1, &inout[0], &inout[1], &inout[2] ); @@ -1250,7 +1254,11 @@ public: %apply (double argout[ANY]) {(double inout[4])}; %apply (double argin[ANY]) {(double inout[4])}; #endif +#if SWIGPYTHON + void _TransformPoint4Double( double inout[4] ) { +#else void TransformPoint( double inout[4] ) { +#endif if (self == NULL) return; OCTTransform4D( self, 1, &inout[0], &inout[1], &inout[2], &inout[3], NULL ); diff --git a/swig/include/python/osr_python.i b/swig/include/python/osr_python.i index 34fac68483f9..c73b99da8087 100644 --- a/swig/include/python/osr_python.i +++ b/swig/include/python/osr_python.i @@ -67,3 +67,28 @@ def _WarnIfUserHasNotSpecifiedIfUsingExceptions(): %} } + +%extend OSRCoordinateTransformationShadow { + +%feature("shadow") TransformPoint %{ + +def TransformPoint(self, *args): + """ + 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) + """ + + import collections.abc + if len(args) == 1 and isinstance(args[0], collections.abc.Sequence): + len_args = len(args[0]) + if len_args == 3: + return self._TransformPoint3Double(args[0]) + elif len_args == 4: + return self._TransformPoint4Double(args[0]) + + return $action(self, *args) +%} + +}