[gdal-dev] OGRSpatialReference problem in QGIS

Florian Hillen fhillen at uni-osnabrueck.de
Mon Aug 17 10:40:44 EDT 2009


Hi list,

I have a problem with OGR, more precisely with OGR in Quantum GIS.

For my Plugin which reprojects rasterdata to another CS, I need a WKT
description of the new CS. With the class "QgsProjectionSelector" of
Quantum GIS I can select a CS and read out the epsg code or the proj4
string. But I fail by setting this to an OGRSpatialReference and export
that to a WKT.
If I transform a 4326 scene with my plugin to 31467 (german system), the
gdal warp works correctly (the coordinates are right), but the information
about the geocs looks like this:

PROJCS["unnamed",PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",1],PARAMETER["false_easting",3500000],PARAMETER["false_northing",0],UNIT["Meter",1]]

Here is the code in which I set the OSR:

    OGRSpatialReference oSRS;

    long epsg = projectSelector->selectedEpsg();

    if(epsg == 0)
        return false;

    if(epsg == 4326)
    {
        QString epsgString;
        epsgString.setNum(epsg);
        epsgString.prepend("EPSG:");
        oSRS.SetWellKnownGeogCS(epsgString.toUtf8());
    }
    else
    {
        oSRS.SetProjCS((projectSelector->selectedName()).toUtf8());
        oSRS.importFromProj4((projectSelector->selectedProj4String()).toUtf8());
    }

    oSRS.exportToWkt( &pszDstWKT );

The if-clause for 4326 was just a try to use an other function, so don't
focus on that too much.

So can anyone help me with that?
Do I have to use the C-API for that? I already had problems with the C++
API of GDAL in Quantum GIS. My first attempt with the C-API for OGR wasn't
successful either, that's why I asked you for a hint.

Thanks in advance and best regards,
Florian


More information about the gdal-dev mailing list