Skip to content

Commit

Permalink
Align raster code improvements
Browse files Browse the repository at this point in the history
 * Fix x/y mismatch
 * Improve strings for translation
 * Remove unrequired cast
  • Loading branch information
m-kuhn committed Apr 8, 2016
1 parent a6aa855 commit b6aee93
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/analysis/raster/qgsalignraster.cpp
Expand Up @@ -193,7 +193,7 @@ bool QgsAlignRaster::setParametersFromRaster( const RasterInfo& rasterInfo, cons
else
{
mGridOffsetX = customGridOffset.x();
mGridOffsetY = customGridOffset.x();
mGridOffsetY = customGridOffset.y();
}
}
else
Expand Down Expand Up @@ -253,8 +253,7 @@ bool QgsAlignRaster::checkInputParameters()
}

mXSize = mYSize = 0;
for ( int i = 0; i < 6; ++i )
mGeoTransform[i] = 0;
std::fill( &mGeoTransform[0], &mGeoTransform[5], 0 );

This comment has been minimized.

Copy link
@rouault

rouault Apr 8, 2016

Contributor

Should end at &mGeoTransform[6]

otherwise:

$ cat test.cpp
#include <algorithm>
#include <stdio.h>

int main(int argc, char* argv[])
{
    double mGeoTransform[6];
    mGeoTransform[5] = -1;
    std::fill( &mGeoTransform[0], &mGeoTransform[5], 1000 );
    printf("%f\n", mGeoTransform[5]);
    return 0;
}
$ g++ test.cpp -o test
$ ./test
-1.000000

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 8, 2016

Author Member

good catch.

you wouldn't have a guess why the raster alignment fails, potentially related to gdal 2?
#2983 (comment)

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Apr 8, 2016

Collaborator

@m-kuhn try nyalldawson@282553e

That was intended to fix it for windows, but for some reason failed on the Travis builds


double finalExtent[4] = { 0, 0, 0, 0 };

Expand Down Expand Up @@ -432,7 +431,7 @@ bool QgsAlignRaster::createAndWarp( const Item& raster )
GDALDatasetH hSrcDS = GDALOpen( raster.inputFilename.toLocal8Bit().constData(), GA_ReadOnly );
if ( !hSrcDS )
{
mErrorMessage = QObject::tr( "Unable to open input file: " ) + raster.inputFilename;
mErrorMessage = QObject::tr( "Unable to open input file: %1" ).arg( raster.inputFilename );
return false;
}

Expand All @@ -448,13 +447,13 @@ bool QgsAlignRaster::createAndWarp( const Item& raster )
if ( !hDstDS )
{
GDALClose( hSrcDS );
mErrorMessage = QObject::tr( "Unable to create output file: " ) + raster.outputFilename;
mErrorMessage = QObject::tr( "Unable to create output file: %1" ).arg( raster.outputFilename );
return false;
}

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

// Copy the color table, if required.
GDALColorTableH hCT = GDALGetRasterColorTable( GDALGetRasterBand( hSrcDS, 1 ) );
Expand Down

0 comments on commit b6aee93

Please sign in to comment.