[gdal-dev] Projection Definition String

Frank Warmerdam warmerdam at pobox.com
Sat Jul 10 10:36:23 EDT 2010


Francois Maass wrote:
> Good day!
> 
> I am trying to set the Projection Definition for a GDALDataset as 
> follows (from the GDALWarp API):
> 
>  
> 
> /const char *pszDstWKT = NULL;/
> /OGRSpatialReference oSRS;/
> /oSRS.SetUTM( 11, TRUE );/
> /oSRS.SetWellKnownGeogCS( "WGS84" );/
> /oSRS.exportToWkt( &pszDstWKT );/
> / /
> /if(GDALSetProjection(srcDataset, pszDstWKT) == CE_Failure)/
> /{ //handle failure/
> /{else/
> /{/
> /            const char *defString = srcDataset->GetProjectionRef();/
> /            cout<<”Length: “<<strlen(defString)<<endl;/
> /cout<<”Projection: ”<<defString<<endl;/
> /};/
> 
>  
> 
> Firstly, I get a compiler error with the oSRS.exportToWKT statement:
> invalid conversion from ‘const char**’ to ‘char**’. 

Francois,

exportToWkt() needs to modify pszDstWKT, so it is inappropriate
for the pointer to be const.

> Secondly, After the GDALSetProjection(…) call succeeds, the projection 
> information is supposed to be printed out to standard out, along with 
> the length of the definition string.
> However, the output is as follows:
>                 $ Length: 0
> 
>                 $ Projection:
> 
>                
> 
> Why is the projection string still empty?  

I see you are seeing the projection on the source file (srcDataset).
Are you sure it is open in update mode?   I suspect that either
the source dataset is not updatable because it is open in read-only
mode or due to a limitation of the driver.  It *ought* to return
CE_Failure in either of those conditions but this is not
always completely properly implemented.  It may be appropriate
for you to file a ticket on why CE_Failure is not returned when
the setprojection seems to be failing.

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