Skip to content
Permalink
Browse files

Fix type of CRS WKT (use just QString instead of both QString and QBy…

…teArray)
  • Loading branch information
wonder-sk committed Jun 25, 2015
1 parent 06b4ad8 commit fcc0160755bd57ec42de4747a370b5b5312dbe57
@@ -20,7 +20,7 @@ class QgsAlignRaster
bool isValid() const;

//! Return CRS in WKT format
QByteArray crs() const;
QString crs() const;
//! Return size of the raster grid in pixels
QSize rasterSize() const;
//! Return number of raster bands in the file
@@ -156,7 +156,7 @@ bool QgsAlignRaster::setParametersFromRaster( const QString& filename, const QSt

bool QgsAlignRaster::setParametersFromRaster( const RasterInfo& rasterInfo, const QString& customCRSWkt, QSizeF customCellSize, QPointF customGridOffset )
{
if ( customCRSWkt.isEmpty() || customCRSWkt.toAscii() == rasterInfo.crs() )
if ( customCRSWkt.isEmpty() || customCRSWkt == rasterInfo.crs() )
{
// use ref. layer to init input
mCrsWkt = rasterInfo.crs();
@@ -198,15 +198,15 @@ bool QgsAlignRaster::setParametersFromRaster( const RasterInfo& rasterInfo, cons
{
QSizeF cs;
QPointF go;
if ( !suggestedWarpOutput( rasterInfo, customCRSWkt.toAscii(), &cs, &go ) )
if ( !suggestedWarpOutput( rasterInfo, customCRSWkt, &cs, &go ) )
{
mCrsWkt = "_error_";
mCellSizeX = mCellSizeY = 0;
mGridOffsetX = mGridOffsetY = 0;
return false;
}

mCrsWkt = customCRSWkt.toAscii();
mCrsWkt = customCRSWkt;

if ( !customCellSize.isValid() )
{
@@ -271,8 +271,8 @@ bool QgsAlignRaster::checkInputParameters()
"File:\n%1\n\n"
"Source WKT:\n%2\n\nDestination WKT:\n%3" )
.arg( r.inputFilename )
.arg( QString::fromAscii( info.mCrsWkt ) )
.arg( QString::fromAscii( mCrsWkt ) );
.arg( info.mCrsWkt )
.arg( mCrsWkt );
return false;
}

@@ -376,7 +376,7 @@ bool QgsAlignRaster::run()
void QgsAlignRaster::dump() const
{
qDebug( "---ALIGN------------------" );
qDebug( "wkt %s", mCrsWkt.constData() );
qDebug( "wkt %s", mCrsWkt.toAscii().constData() );
qDebug( "w/h %d,%d", mXSize, mYSize );
qDebug( "transform" );
qDebug( "%6.2f %6.2f %6.2f", mGeoTransform[0], mGeoTransform[1], mGeoTransform[2] );
@@ -421,7 +421,7 @@ bool QgsAlignRaster::createAndWarp( const Item& raster )
}

// Write out the projection definition.
GDALSetProjection( hDstDS, mCrsWkt.constData() );
GDALSetProjection( hDstDS, mCrsWkt.toAscii().constData() );
GDALSetGeoTransform( hDstDS, ( double* )mGeoTransform );

// Copy the color table, if required.
@@ -482,13 +482,13 @@ bool QgsAlignRaster::createAndWarp( const Item& raster )
return true;
}

bool QgsAlignRaster::suggestedWarpOutput( const QgsAlignRaster::RasterInfo& info, const QByteArray& destWkt, QSizeF* cellSize, QPointF* gridOffset, QgsRectangle* rect )
bool QgsAlignRaster::suggestedWarpOutput( const QgsAlignRaster::RasterInfo& info, const QString& destWkt, QSizeF* cellSize, QPointF* gridOffset, QgsRectangle* rect )
{
// Create a transformer that maps from source pixel/line coordinates
// to destination georeferenced coordinates (not destination
// pixel line). We do that by omitting the destination dataset
// handle (setting it to NULL).
void* hTransformArg = GDALCreateGenImgProjTransformer( info.mDataset, info.mCrsWkt.constData(), NULL, destWkt.constData(), FALSE, 0, 1 );
void* hTransformArg = GDALCreateGenImgProjTransformer( info.mDataset, info.mCrsWkt.toAscii().constData(), NULL, destWkt.toAscii().constData(), FALSE, 0, 1 );
if ( !hTransformArg )
return false;

@@ -533,7 +533,7 @@ QgsAlignRaster::RasterInfo::RasterInfo( const QString& layerpath )
GDALGetGeoTransform( mDataset, mGeoTransform );

// TODO: may be null or empty string
mCrsWkt = QByteArray( GDALGetProjectionRef( mDataset ) );
mCrsWkt = QString::fromAscii( GDALGetProjectionRef( mDataset ) );

mBandCnt = GDALGetBandNumber( mDataset );
}
@@ -568,7 +568,7 @@ QPointF QgsAlignRaster::RasterInfo::origin() const
void QgsAlignRaster::RasterInfo::dump() const
{
qDebug( "---RASTER INFO------------------" );
qDebug( "wkt %s", mCrsWkt.constData() );
qDebug( "wkt %s", mCrsWkt.toAscii().constData() );
qDebug( "w/h %d,%d", mXSize, mYSize );
qDebug( "cell x/y %f,%f", cellSize().width(), cellSize().width() );

@@ -52,7 +52,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
bool isValid() const { return mDataset != 0; }

//! Return CRS in WKT format
QByteArray crs() const { return mCrsWkt; }
QString crs() const { return mCrsWkt; }
//! Return size of the raster grid in pixels
QSize rasterSize() const { return QSize( mXSize, mYSize ); }
//! Return number of raster bands in the file
@@ -76,7 +76,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
//! handle to open GDAL dataset
GDALDatasetH mDataset;
//! CRS stored in WKT format
QByteArray mCrsWkt;
QString mCrsWkt;
//! geotransform coefficients
double mGeoTransform[6];
//! raster grid size
@@ -155,7 +155,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }

//! Set the output CRS in WKT format
void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt.toAscii(); }
void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt; }
//! Get the output CRS in WKT format
QString destinationCRS() const { return mCrsWkt; }

@@ -211,7 +211,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
bool createAndWarp( const Item& raster );

//! Determine suggested output of raster warp to a different CRS. Returns true on success
static bool suggestedWarpOutput( const RasterInfo& info, const QByteArray& destWkt, QSizeF* cellSize = 0, QPointF* gridOffset = 0, QgsRectangle* rect = 0 );
static bool suggestedWarpOutput( const RasterInfo& info, const QString& destWkt, QSizeF* cellSize = 0, QPointF* gridOffset = 0, QgsRectangle* rect = 0 );

protected:

@@ -227,7 +227,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
List mRasters;

//! Destination CRS - stored in well-known text (WKT) format
QByteArray mCrsWkt;
QString mCrsWkt;
//! Destination cell size
double mCellSizeX, mCellSizeY;
//! Destination grid offset - expected to be in interval <0,cellsize)
@@ -161,7 +161,7 @@ void QgsAlignRasterDialog::updateParametersFromReferenceLayer()
// get custom values from the GUI (if any)
if ( mChkCustomCRS->isChecked() )
{
QgsCoordinateReferenceSystem refCRS( QString::fromAscii( refInfo.crs() ) );
QgsCoordinateReferenceSystem refCRS( refInfo.crs() );
if ( refCRS != mCrsSelector->crs() )
customCRSWkt = mCrsSelector->crs().toWkt();
}
@@ -270,7 +270,7 @@ void QgsAlignRasterDialog::referenceLayerChanged()
if ( !refInfo.isValid() )
return;

QgsCoordinateReferenceSystem layerCRS( QString::fromAscii( refInfo.crs() ) );
QgsCoordinateReferenceSystem layerCRS( refInfo.crs() );
mCrsSelector->setLayerCrs( layerCRS );
mClipExtentGroupBox->setOriginalExtent( refInfo.extent(), layerCRS );

@@ -224,7 +224,7 @@ class TestAlignRaster : public QObject

QgsAlignRaster::RasterInfo out( tmpFile );
QVERIFY( out.isValid() );
QgsCoordinateReferenceSystem outCRS( QString::fromAscii( out.crs() ) );
QgsCoordinateReferenceSystem outCRS( out.crs() );
QCOMPARE( outCRS, destCRS );
QCOMPARE( out.rasterSize(), QSize( 4, 4 ) );
// let's stick to integers to keep the test more robust

0 comments on commit fcc0160

Please sign in to comment.
You can’t perform that action at this time.