[Gdal-dev] c# corner coordinates in latitude / longitude?

coastalrocket andy at planetnomad.com
Tue Sep 1 10:49:16 EDT 2009


Hello all,

I'm very much new to GDAL and have been for the last couple of days
following the c# implementation examples. I have noticed that the corner
coordinates output of gdalinfo for my image will contain the projected
coordinate values followed by the unprojected latitude / longitude values. I
have not been able to find a similar technique in the c# examples or through
the class descriptions. I suppose I can take the projection information and
turn to Proj4 to convert the projected coordinates but since gdalinfo in
command line form is spitting out these values I thought they would be
available through the c# gdal libraries. Is this the case or am i missing
something?

Many thanks,
Andrew

In the example GDALInfo.cs

Console.WriteLine( "Corner Coordinates:" );
            Console.WriteLine("  Upper Left (" + GDALInfoGetPosition( ds,
0.0, 0.0) + ")");
            Console.WriteLine("  Lower Left (" + GDALInfoGetPosition( ds,
0.0, ds.RasterYSize) + ")");
            Console.WriteLine("  Upper Right (" + GDALInfoGetPosition( ds,
ds.RasterXSize, 0.0) + ")");
            Console.WriteLine("  Lower Right (" + GDALInfoGetPosition( ds,
ds.RasterXSize, ds.RasterYSize) + ")");
            Console.WriteLine("  Center (" + GDALInfoGetPosition( ds,
ds.RasterXSize / 2, ds.RasterYSize / 2) + ")");
            Console.WriteLine("");

and..

private static string GDALInfoGetPosition(Dataset ds, double x, double y)
    {
        double[] adfGeoTransform = new double[6];
        double  dfGeoX, dfGeoY;
        ds.GetGeoTransform(adfGeoTransform);

        dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x +
adfGeoTransform[2] * y;
        dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x +
adfGeoTransform[5] * y;

        return dfGeoX.ToString() + ", " + dfGeoY.ToString();
    }

Example of gdalinfo..

Corner Coordinates: 
Upper Left  (  228000.000,   22200.000) (  2d 2'53.37"E,  0d12'2.77"N) 
Lower Left  (  228000.000,   22000.000) (  2d 2'53.37"E,  0d11'56.26"N) 
Upper Right (  228200.000,   22200.000) (  2d 2'59.84"E,  0d12'2.77"N) 
Lower Right (  228200.000,   22000.000) (  2d 2'59.84"E,  0d11'56.26"N) 
Center      (  228100.000,   22100.000) (  2d 2'56.61"E,  0d11'59.51"N) 

Apologies if this post appears twice. My first was rejected through me not
subscribing before sending. 
-- 
View this message in context: http://n2.nabble.com/c-corner-coordinates-in-latitude-longitude-tp3560997p3560997.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list