[gdal-dev] Fwd: C++ Transformation from Lat-Long coords to UTM

Pierpaolo Polo pierpaolo.polo at gmail.com
Tue Sep 15 07:28:52 PDT 2015


Hi,

i'm reading a lot of sources from internet trying to explain how to make
this transformation from coordintates as:
  V_LATITUDE = '9,54153844';
  V_LONGITUDE = '39,44322841';

Into UTM values.
We have a tiff map with a tfw file as follows:
50.0000000000
0.0000000000
0.0000000000
-50.0000000000
706876.2384142603
5976388.9235886401

As far as i read online, I've to use two OGRSpatialReference
<http://www.gdal.org/classOGRSpatialReference.html> using one as the
"destination" format and the second one as source format. But I don't
understand how to set up the "origin" reference to accept latitude and
longitude.
>From OGR tutorial i see this snippet:

    OGRSpatialReference
<http://www.gdal.org/classOGRSpatialReference.html>    oUTM,
*poLatLong;
    OGRCoordinateTransformation
<http://www.gdal.org/classOGRCoordinateTransformation.html>
*poTransform;

    oUTM.SetProjCS
<http://www.gdal.org/classOGRSpatialReference.html#a208118581246feb29646acf2ea5d4237>("UTM
17 / WGS84");
    oUTM.SetWellKnownGeogCS
<http://www.gdal.org/classOGRSpatialReference.html#a096b8dde4fd2eb475acd376060940b02>(
"WGS84" );
    oUTM.SetUTM
<http://www.gdal.org/classOGRSpatialReference.html#a0c4f6fcab663c9eb6d465787cad3833c>(
17 );

    poLatLong = oUTM.CloneGeogCS
<http://www.gdal.org/classOGRSpatialReference.html#a0c1e2b108255487f91ae448f5c11f67c>();

    poTransform = OGRCreateCoordinateTransformation
<http://www.gdal.org/ogr__spatialref_8h.html#aae11bd08e45cdb2e71e1d9c31f1e550f>(
&oUTM, poLatLong );
    if( poTransform == NULL )
    {
        ...
    }

    ...

    if( !poTransform->Transform
<http://www.gdal.org/classOGRCoordinateTransformation.html#abf141396940b4f7b1f8118ea025d569b>(
nPoints, x, y, z ) )
    ...


I know how to obtain UTM zone (as floor[(longitude+180)/6]+1) but i'm not
understanding if the call to Transform will take my longitude/latitude
values or if i'll obtain a "complete" transformation from a reference
system to another.
The target is to access a GDALRasterBand and obtain a pixel value starting
with returned coordinates.

Thanks and regards,
Pierpaolo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150915/ccd8fe84/attachment.html>


More information about the gdal-dev mailing list