[gdal-dev] Problem with GDALGetProjectionRef

Florian Hillen fhillen at uni-osnabrueck.de
Mon Aug 24 08:03:15 EDT 2009


Hi list,

I was wondering why GDALGetProjectionRef delivers an other result than
gdalinfo from FWTools of course by using the same file.

Here is my code from my qgis plugin:

    if( GDALGetProjectionRef( inputDS ) != NULL )
    {
        OGRSpatialReferenceH inputSRS;
        char *pszProjection;

        pszProjection = (char *) GDALGetProjectionRef( inputDS );

        inputSRS = OSRNewSpatialReference(NULL);
        if( OSRImportFromWkt( inputSRS, &pszProjection ) == CE_None )
        {
            char *prettyWkt = NULL;

            OSRExportToPrettyWkt( inputSRS, &prettyWkt, FALSE );

            QString wktFormat = prettyWkt;
            wktFormat.replace(QString("\n"), QString("<br>"));

            information += "<tr><td>";
            information += tr( "<b>Coordinate System:</b><br>" );
            information += wktFormat;
            information += "</td></tr>";
            CPLFree( prettyWkt );
        }
        else
        {
            information += "<tr><td>";
            information += tr( "<b>Coordinate System11:</b><br> %1" )
                            .arg( GDALGetProjectionRef( inputDS ) );
            information += "</td></tr>";
        }

        OSRDestroySpatialReference( inputSRS );
    }

and the same part from gdalinfo:

    if( GDALGetProjectionRef( hDataset ) != NULL )
    {
        OGRSpatialReferenceH  hSRS;
        char		      *pszProjection;

        pszProjection = (char *) GDALGetProjectionRef( hDataset );

        hSRS = OSRNewSpatialReference(NULL);
        if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None )
        {
            char	*pszPrettyWkt = NULL;

            OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE );
            printf( "Coordinate System is:\n%s\n", pszPrettyWkt );
            CPLFree( pszPrettyWkt );
        }
        else
            printf( "Coordinate System is `%s'\n",
                    GDALGetProjectionRef( hDataset ) );

        OSRDestroySpatialReference( hSRS );
    }

gdalinfo delivers the right projection:

PROJCS["unnamed",
    GEOGCS["DHDN",
        DATUM["Deutsches_Hauptdreiecksnetz",
            SPHEROID["Bessel 1841",6377397.155,299.1528128000009,
                AUTHORITY["EPSG","7004"]],
            AUTHORITY["EPSG","6314"]],
[...]

GDALGetProjectionRef delivers the following WKT string (some of you know
this from some earlier mails):

PROJCS["unnamed",
GEOGCS["DHDN",
DATUM["unknown",
SPHEROID["unretrievable - using WGS84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4314"]],
[...]

In the earlier mails I thought that the warp doesn't work correct, but
apparently the warp is correct, because I use the same file for gdalinfo
and in my plugin. So the problem must be GDALGetProjectionRef!?

Can anyone help me with that?

Best regards,
Florian


More information about the gdal-dev mailing list