[Gdal-dev] Query regarding coordinate system transformation using
GDAL
Frank Warmerdam
warmerdam at pobox.com
Tue Jul 10 13:01:24 EDT 2007
viritha 30 wrote:
> Hi Friends,
>
> I am working on GDAL library. I have some doubts in
> using it. I want to convert the geographic coordinate system into any
> other projection coordinate system. That is. i want the converted values
> of WGS84 latitude and longitude values in any other projection
> coordinate system like UTM or Mercator2SP.......etc. And also i want to
> retrieve the zone number from this . If anyone know abou this convertion
> using GDAL library or OGRSpatial Reference class, please mail me. its
> very urgent for me.
>
> I am giving the code i am working. i dont know how to go forward . plz
> help me. i am doing it in VC++ on Windows.
>
> {
> OGRSpatialReference osRS,oosRS ;
> char *pszWKT=NULL;
> char *pszaWKT=NULL;
> CString str;
>
> osRS.SetWellKnownGeogCS("WGS84");
> osRS.exportToWkt(&pszWKT);
> str.Format("%s",pszWKT);
> MessageBox(str);
>
>
> oosRS.SetProjCS("Mercator_2SP");
> oosRS.SetWellKnownGeogCS("EPSG:9805");
> oosRS.SetHOM(0, 75, 90.0, 90.0,1.0, 500000, 0);
> oosRS.exportToWkt(&pszaWKT);
> str.Format("%s",pszaWKT);
> MessageBox(str);
Viritha,
You are doing well up to this point. Are you wanting to create a
transformer object that you can use to transform individual points
you pass in programmatically, or to warp a raster? The
GDALCreateReprojectionTransformer() is really for use warping rasters.
If you just want transform individual points you pass in you should use
the OGRCoordinateTransformation class instead. It's use is described
near the end of the OGR Projections Tutorial at:
http://www.gdal.org/ogr/osr_tutorial.html
> I even tried with the OGRCreateCoordinateTransformation()
> function. by passing the two coordinate systems in WKT format. still i
> was strucked.
Ah, I see you were already aware of this.
Perhaps you didn't see the specific example in the tutorial under the
title "Coordinate Transformation"? Note that you use the OGRSpatialReference
objects, not the raw WKT to create this transformer. For brevity the
example given looks like this:
OGRSpatialReference oSourceSRS, oTargetSRS;
OGRCoordinateTransformation *poCT;
double x, y;
oSourceSRS.importFromEPSG( atoi(papszArgv[i+1]) );
oTargetSRS.importFromEPSG( atoi(papszArgv[i+2]) );
poCT = OGRCreateCoordinateTransformation( &oSourceSRS,
&oTargetSRS );
x = atof( papszArgv[i+3] );
y = atof( papszArgv[i+4] );
if( poCT == NULL || !poCT->Transform( 1, &x, &y ) )
printf( "Transformation failed.\n" );
else
printf( "(%f,%f) -> (%f,%f)\n",
atof( papszArgv[i+3] ),
atof( papszArgv[i+4] ),
x, y );
You should be able to use your osRS and oosRS objects in
place of oSourceSRS and oTargetSRS.
I'm not aware of a method to compute the idea UTM zone for a given
longitude but a UTM zone is generally considered to extend 3 degrees
out from either side of it's central meridian and the central meridian
can be computed as "nZone * 6 - 183".
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 | President OSGeo, http://osgeo.org
More information about the Gdal-dev
mailing list