[gdal-dev] Projection Definition String

Francois Maass fieliesm at gmail.com
Sat Jul 10 11:10:54 EDT 2010


Hi Frank

Thank you for your suggestion.
I realized that I opened my dataset with GA_ReadOnly, and now changed it to
GA_Update.

Now another issues presented itself:
When I execute these statements on a .pix image, it works beautifully. 
When I execute these statements on a .TIF image, it still gives an empty
definition string, with the CPLError stil CE_None.

Am I supposed to manually include any additional GeoTiff or Tiff libraries
when I build my application? 

-----Original Message-----
From: Frank Warmerdam [mailto:warmerdam at pobox.com] 
Sent: Saturday, July 10, 2010 4:36 PM
To: Francois Maass
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Projection Definition String

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