I'm in a puzzle of figuring out how to create correct coordinate transformations using GDAL C/C++ API. I have referenced code from tutorial - https://gdal.org/tutorials/osr_api_tut.html#coordinate-transformation Input coordinate references would be based on Sentinel-2 dataset over Estonia. Hence source SRS - EPSG:32635 (WGS 84 / UTM 35N). Destination SRS - EPSG:3301 (Estonian Coordinate System of 1997).
When running the tutorial example as (args - {source EPSG} {dest EPSG} {lon} {lat}):
gdal-srs 32635 3301 499980 6500040
Result would be
(499980.000000,6500040.000000) -> (6503984.251806,674129.197242)
I tried the same with the following python tutorial example - https://pcjericks.github.io/py-gdalogr-cookbook/projection.html#reproject-a-geometry Results are the same. Also tried specifying options with SetAreaOfInterest()
- still no change.
To make sure the installation is not messed up (GDAL 3.0.4 official apt package for Ubuntu 20.04), the following gdal_retile command produces correct coordinates for output tiles (Same tool is used for reference too)
gdal_retile.py -ps 512 512 -overlap 32 -of Gtiff -s_srs 'EPSG:3301' -targetDir tiled_multi T35VNE_20211102T093049_B8A.jp2
I have debugged gdal_retile.py source code but I have not understood what it does differently. In practice this transformation between these EPSGs should not actually change the input coordinates, but the functionality should expect all the projections to be supported that GDAL/PROJ supports.
gdal_retile.py -ps 512 512 -overlap 32 -of Gtiff -s_srs 'EPSG:3301' -targetDir tiled_multi T35VNE_20211102T093049_B8A.jp2
is converting the input dataset's EPSG:32635 coordinates to EPSG:3301 and they are not changed, due to the fact that input projection is in a UTM zone that is similar to EPSG:3301's (covering Estonia). Therefore I think gdal tools' output should be the template here.