Skip to content

Commit

Permalink
Use epsg number for output crs in rastercalculator if possible (ticket
Browse files Browse the repository at this point in the history
…#3649)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15815 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 23, 2011
1 parent 732325d commit 6e2f964
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/analysis/raster/qgsrastercalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QProgressDialog>

#include "gdalwarper.h"
#include <ogr_srs_api.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
Expand Down Expand Up @@ -117,8 +118,21 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
QgsRasterLayer* rl = mRasterEntries.at( 0 ).raster;
if ( rl )
{
//proj format would be better, but is not supported e.g. for writing to GeoTiff
GDALSetProjection( outputDataset, TO8( rl->crs().toWkt() ) );
char* crsWKT = 0;
OGRSpatialReferenceH ogrSRS = OSRNewSpatialReference( NULL );
const QgsCoordinateReferenceSystem& outputCrs = rl->crs();
int epsgCode = outputCrs.epsg();
if ( epsgCode > 0 && OSRImportFromEPSG( ogrSRS, epsgCode ) == CE_None )
{
OSRExportToWkt( ogrSRS, &crsWKT );
GDALSetProjection( outputDataset, crsWKT );
}
else
{
GDALSetProjection( outputDataset, TO8( rl->crs().toWkt() ) );
}
OSRDestroySpatialReference( ogrSRS );
CPLFree( crsWKT );
}
}

Expand Down

0 comments on commit 6e2f964

Please sign in to comment.