[OSGeo-UK] Fw: Get Lat/Long/Altitude data from GeoTiff File

Matt Travis matt.travis1 at gmail.com
Fri Feb 19 08:08:20 PST 2021


You're probably going to get more assistance with this if you post it on
the gdal-dev list
http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html

Thanks

Matt

On Fri, 19 Feb 2021 at 15:50, Wael El-Sayegh <wael_elsayegh at hotmail.com>
wrote:

>
>
>
>
>
> I am trying to obtain and convert latitude and longitude and altitude
> values into British National Grid coordinates from GeoTIFF using GDAL C#
> file, I managed to read the coordinate system and corner coordinates as
>
> The thing is, since that GDAL is more of Python documentation and I can't
> go through it, I am not sure what is the next step or how to do it using
> SpatialReference() and CoordinateTransformation().
>
> This is the code I tried so far but still getting the wrong numbers, I
> think its because they are projected coordinate system and needed to be
> converted in British coordinate system.
>
> How can I do this?
>
>
>
> PS: I am not sure if the XY coordinates are right, also not sure how to
> read Z coordinates.
>
>
>
> Looking forward to hearing from you
>
>
>
> GdalConfiguration.ConfigureGdal();
>
>             GdalConfiguration.ConfigureOgr();
>
>             Gdal.AllRegister();
>
>
>
>             Dataset ds = Gdal.Open(fileName, Access.GA_ReadOnly);
>
>
>
>
>
>
>
>
>
>             double[] gt = new double[6];
>
>             int Rows = ds.RasterYSize;
>
>             int Cols = ds.RasterXSize;
>
>             double startX = gt[0];
>
>             double startY = gt[3];
>
>             double interval;
>
>             Band band = ds.GetRasterBand(1);
>
>             double xx, y;
>
>
>
>             for (int k = 0; k < Rows; k++)
>
>             {
>
>
>
>                 ds.GetGeoTransform(gt);
>
>
>
>                 interval = gt[1];
>
>                 ds.GetGeoTransform(gt);
>
>                 y = startY - k * interval; //Current lat
>
>                 int[] buf = new int[Cols];
>
>                 //ReadRaster parameters are StartCol, StartRow,
> ColumnsToRead, RowsToRead, BufferToStoreInto, BufferColumns, BufferRows, 0,
> 0
>
>                 band.ReadRaster(0, k, Cols, 1, buf, Cols, 1, 0, 0);
>
>                 //iterate each item in one line
>
>                 for (int r = 0; r < Cols; r++)
>
>                 {
>
>                     row = XYZData.NewRow();
>
>                     if (buf[r] != -32768)   //if pixel value is not NoData
> value
>
>                     {
>
>                         xx = startX + r * interval;  //current lon
>
>
>
>                         SpatialReference srs = new
> SpatialReference("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601271625
> +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs");
>
>
>
>                         SpatialReference dst = new SpatialReference("");
>
>                         dst.ImportFromProj4("+proj=longlat +ellps=WGS84
> +datum=WGS84 +no_defs");
>
>
>
>
>
>                         double[] p = new double[3];
>
>                         p[0] = xx;
>
>                         p[1] = y;
>
>                         p[2] = 0;
>
>
>
>                         var coordinateTransform = new
> CoordinateTransformation(srs, dst);
>
>
>
>                         coordinateTransform.TransformPoint(p);
>
>
>
>                         var latLong = new LatitudeLongitude(p[1], p[0]);
>
>                         var cartesian = GeoUK.Convert.ToCartesian(new
> Wgs84(), latLong);
>
>
>
>                         row["X"] = cartesian.X;
>
>                         row["Y"] = cartesian.Y;
>
>                         row["Z"] = 0;
>
>                         XYZData.Rows.Add(row.ItemArray);
>
>
>
>
>
>                     }
>
>
>
> _______________________________________________
> UK mailing list
> UK at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/uk/attachments/20210219/9761a467/attachment.html>


More information about the UK mailing list