Skip to content

Commit

Permalink
Merge pull request #8116 from rouault/fix_swig_python_bindings_warnings
Browse files Browse the repository at this point in the history
Fix swig python bindings warnings
  • Loading branch information
rouault authored Jul 19, 2023
2 parents df3f866 + c070782 commit ff5a515
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
15 changes: 15 additions & 0 deletions autotest/osr/osr_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion swig/include/ogr.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions swig/include/osr.i
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
Expand All @@ -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 );
Expand Down
25 changes: 25 additions & 0 deletions swig/include/python/osr_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -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)
%}

}

0 comments on commit ff5a515

Please sign in to comment.