Skip to content

Commit

Permalink
[QGIS-Server][WCS] Add RESPONSE_CRS param
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Feb 7, 2014
1 parent 408e2b7 commit da8ca46
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/mapserver/qgswcsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,16 @@ QByteArray* QgsWCSServer::getCoverage()
{
mErrors << QString( "The CRS is mandatory" );
}
QgsCoordinateReferenceSystem outputCRS = QgsCRSCache::instance()->crsByAuthId( crs );
if ( !outputCRS.isValid() )

if ( mErrors.count() != 0 )
{
mErrors << QString( "Could not create output CRS" );
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
}

if ( mErrors.count() != 0 )
QgsCoordinateReferenceSystem requestCRS = QgsCRSCache::instance()->crsByAuthId( crs );
if ( !requestCRS.isValid() )
{
mErrors << QString( "Could not create request CRS" );
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
}

Expand All @@ -277,6 +279,25 @@ QByteArray* QgsWCSServer::getCoverage()
QgsRasterLayer* rLayer = dynamic_cast<QgsRasterLayer*>( layer );
if ( rLayer && wcsLayersId.contains( rLayer->id() ) )
{
// RESPONSE_CRS
QgsCoordinateReferenceSystem responseCRS = rLayer->crs();
crs = mParameterMap.value( "RESPONSE_CRS", "" );
if ( crs != "" )
{
responseCRS = QgsCRSCache::instance()->crsByAuthId( crs );
if ( !responseCRS.isValid() )
{
responseCRS = rLayer->crs();
}
}

// transform rect
if ( requestCRS != rLayer->crs() )
{
QgsCoordinateTransform t( requestCRS, rLayer->crs() );
rect = t.transformBoundingBox( rect );
}

QTemporaryFile tempFile;
tempFile.open();
QgsRasterFileWriter fileWriter( tempFile.fileName() );
Expand All @@ -290,18 +311,18 @@ QByteArray* QgsWCSServer::getCoverage()
}

// add projector if necessary
if ( outputCRS != rLayer->crs() )
if ( responseCRS != rLayer->crs() )
{
QgsRasterProjector * projector = new QgsRasterProjector;
projector->setCRS( rLayer->crs(), outputCRS );
projector->setCRS( rLayer->crs(), responseCRS );
if ( !pipe->insert( 2, projector ) )
{
mErrors << QString( "Cannot set pipe projector" );
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
}
}

QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, width, height, rect, outputCRS );
QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, width, height, rect, responseCRS );
if ( err != QgsRasterFileWriter::NoError )
{
mErrors << QString( "Cannot write raster error code: %1" ).arg( err );
Expand Down

0 comments on commit da8ca46

Please sign in to comment.