[Gdal-dev] Lat/Lon to UTM conversion

Frank Warmerdam fwarmerdam at gmail.com
Tue Mar 22 10:03:21 EST 2005


On Tue, 22 Mar 2005 15:27:54 +0100, Michele Sanges
<michele.sanges at otomelara.it> wrote:
> In order to convert a geographic coordinate (lat/lon - WGS84) to a projected coordinate (UTM - NAD83), I writted the following code:
> 
> > OGRSpatialReference oUTM;
> > oUTM.SetWellKnownGeogCS( "NAD83" ); // the target reference system
> > OGRCoordinateTransformation *poTransform=OGRCreateCoordinateTransformation(&m_oSRS, &oUTM); // m_oSRS is the source reference system (WGS84)
>  > if (poTransform == NULL)
>  >      return;
>  >
>  > poTransform->Transform( 1, pfXproj, pfYproj );
>  > delete poTransform;
> 
> It don't works, the Transform function returns TRUE, but the coordinate (*pfXproj,*pfYproj) remain immutate.
> Moreover, how can I find the UTM zone?

Michele, 

First of all, you haven't done anything to actually make oUTM 
a UTM definition.  So you are effectively just trying to convert
from m_oSRS (presumably WGS84) to NAD83 which to the system
are considered identical.   Hence, no change. 

I think you want something like:

   OGRSpatialReference oUTM
   
   oUTM.SetUTM( 11 );
   oUTM.SetWellKnownGeogCS( "NAD83" );

    ...

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list