2

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"]]

1

1 Answer 1

1

You don't say, but I'm assuming the PROJCS string in your question is the string being read from your dataset. There are several errors in the string. Here's what I found on SpatialReference.org:

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,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]],
UNIT["metre",1,
    AUTHORITY["EPSG","9001"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",63],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
AUTHORITY["EPSG","32641"],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]

Your central meridian is wrong, as is the false easting.

2
  • thanks for your response. when I open this image with "global mapper", it shows correct lat/long. how that sofware can generate desired results if the string have errors? Aug 31, 2014 at 20:47
  • about all I can guess is that GlobalMapper is reading just the EPSG value, or even the UTM 41 zone 41N, and ignoring the actual projection parameters in the string
    – Llaves
    Aug 31, 2014 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.