Here is the function that I use to convert from pixel x,y to lat,lon coordinate:
public static Coordinate imageToWorld(Dataset gds, int x, int y)
{
double[] adfGeoTransform = new double[6];
double[] p = new double[3];
gds.GetGeoTransform(adfGeoTransform);
p[0] = adfGeoTransform[0] + adfGeoTransform[1] * x + adfGeoTransform[2] * y;
p[1] = adfGeoTransform[3] + adfGeoTransform[4] * x + adfGeoTransform[5] * y;
OSGeo.OSR.SpatialReference src = new OSGeo.OSR.SpatialReference("");
string s = gds.GetProjectionRef();
src.ImportFromWkt(ref s);
//src.SetUTM(41, 1);
OSGeo.OSR.SpatialReference wgs84 = new OSGeo.OSR.SpatialReference("");
wgs84.SetWellKnownGeogCS("WGS84");
OSGeo.OSR.CoordinateTransformation ct = new OSGeo.OSR.CoordinateTransformation(src, wgs84);
ct.TransformPoint(p);
return new Coordinate(p[0], p[1]);
}
but this function doesn't work for utm projection and gives incorrect longitude. for example for an image with the following WKT it gives 35.25,3.65 but it should be 35.29,61.17 @(x=0,y=0). if I uncomment line 12 it gives correct result only for this image.
PROJCS["WGS 84 / UTM zone 41N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32641"]]