[Gdal-dev] I need some help on using the SetMercator method

Rawlinson, John (UK) JRAWLINSON at ngms.eu.com
Thu Dec 29 12:51:25 EST 2005


I'm having some problems with the SetMercator method of OGRSpatialReference when using the GDAL Warp API. I'm writing an app the reads GeoTiff files and warps them into a memory raster. Things are ok without setting the target raster to be projected i.e.  

	oSRS.SetWellKnownGeogCS( "WGS84" );
	oSRS.exportToWkt( &pszSRS_WKT );
	poDstDS->SetGeoTransform( adfGeoTransform );
	poDstDS->SetProjection( pszSRS_WKT );

Source data is transferred to target raster correctly by the warp operation.

Note: I have previously calculated the GeoTransform array as follows:

	adfGeoTransform[0] = tl_lon;

	if (br_lon > tl_lon)
	{
		adfGeoTransform[1] = (br_lon - tl_lon) / iwidth;
	}
	else
	{
		adfGeoTransform[1] = (br_lon + 360.0 - tl_lon) / iwidth;
	}
	adfGeoTransform[2] = 0;
	
	adfGeoTransform[3] = tl_lat;
	adfGeoTransform[4] = 0;
	adfGeoTransform[5] = ((br_lat - tl_lat) / iheight);

Where tl_lat, tl_lon, br_lat, br_lon are the geographic extents of my target raster and iwidth and iheight are the raster sizes.

As soon as I set the target raster to be projected i.e.

	oSRS.SetProjCS("Mercator Projection");
	oSRS.SetWellKnownGeogCS( "WGS84" );
        oSRS.SetMercator (0, 0, 1.0, 0, 0);
	oSRS.exportToWkt( &pszSRS_WKT );
	poDstDS->SetGeoTransform( adfGeoTransform );
	poDstDS->SetProjection( pszSRS_WKT );

Now the target raster is not filled (all black). I've experimented a little with the parameters to the SetMercator method. Setting the scale factor to 0 caused one of my tiff files (large map of europe) to warp ok, however, a small map ~300km wide in Afghanistan didn't warp (all black in the target again).

Can anyone advise on what the parameters passed to SetMercator should be? Also, what does scale factor mean in this context? Is there anything else I should be doing?

Many thanks for any help anyone can give.

Best regards,

John Rawlinson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20051229/1cb92db1/attachment.html


More information about the Gdal-dev mailing list