[gdal-dev] Using GDAL.Transformer from C#

Tamas Szekeres szekerest at gmail.com
Thu Oct 16 17:07:18 EDT 2008


Hi,

Here is an example extracted from the gdalinfo.cs sample application
(http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/GDALInfo.cs)

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();
}


Best regards,

Tamas



2008/10/16 Reed Copsey, Jr. <reedc+gdal at ctech.com>:
> I'm looking for the best approach to figuring out the specific projected
> coordinate of a raster read via the GDAL C# wrappers.
> If I open a dataset using Gdal.Open(...) which has projection information,
> what is the best way in C# to determine the actual coordinate of a specific
> pixel?
>
> For example, I want to determine where, in projected space, the pixel at
> [50,25] in image coordinates might lie.
> Right now, I'm calculating this by hand using the
> dataset.GetGeoTransform(...) array, but this is less simple if the
> transformation isn't simple.  I'd ideally like a solution that works with
> GCP defined datasets, as well.
> It looks like GDAL.Transformer is the way to go here, but the C# wrappers
> only seem to work by taking a dataset to project from and to, and then
> transforming a coordinate from one to the other.  Is the best approach to
> create a dataset in memory with 1 pixel wide spacing, located at the origin,
> and use that as from and the loaded dataset as the "to" dataset?  Is there
> an easier/simpler/faster approach?
> Thank you,
> Reed Copsey
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>


More information about the gdal-dev mailing list