[Gdal-dev] OGRSpatialReference::exportToProj4 causes segmentation
error
Frank Warmerdam
warmerdam at pobox.com
Wed Jul 28 13:41:02 EDT 2004
Xiaodong Zhang wrote:
> Hi,
>
> One of our code, which works with Gdal 1.1.8 causes a segmentation fault with
> newer version of Gdal 1.1.9 and Gdal 1.2.1. It seemed that the following part
> causes the problem.
>
> char ** ppProj;
> ....
> proj = srcDataset->GetProjectionRef();
> /* so far is OK after open an image with GDALOpen and get the projection info
>
> OGRSpatialReference hProj(proj); // it is still OK up to here
> hProj.exportToProj4 (ppProj); // it crashes here
>
> Also the OGR documentation says to de-allocate ppProj using CPLfree(), how to
> use it exactly?
Hi,
You need to pass a pointer to a pointer where the resulting string can be
assigned. I'm not sure why it would work with 1.1.8 unless it was just a
coincidental thing about where the unitialized ppProj pointed.
It should be something like:
char **pszProjWKT = NULL;
OGRSpatialReferenceh oProj( srcDataset->GetProjectionRef() );
oProj.exportToProj4( &pszProjWKT );
printf( "%s", pszProjWKT );
CPLFree( pszProjWKT );
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