[gdal-dev] problems with gdal_merge.py

Volker Wichmann Volker.Wichmann at uibk.ac.at
Wed Apr 23 06:20:26 EDT 2008


Frank,

I've updated to 1.5.1: my former problem disappeared, but  NOW the ersi 
ascii is off by half a pixel. I think the georeferencing is handled 
incorrectly by the driver.
Patching the driver with the following lines works for me:

in file aaigriddataset.cpp:

line 447
- poDS->adfGeoTransform[0] = atof( papszTokens[i + 1] );
+ poDS->adfGeoTransform[0] = atof( papszTokens[i + 1] ) + 0.5 * dfCellDX;


line 450
- poDS->adfGeoTransform[3] = atof( papszTokens[j + 1] )
            + poDS->nRasterYSize * dfCellDY;
+ poDS->adfGeoTransform[3] = atof( papszTokens[j + 1] ) - 0.5 * dfCellDX
            + poDS->nRasterYSize * dfCellDY;


line 460
- poDS->adfGeoTransform[0] = atof(papszTokens[i + 1]) - 0.5 * dfCellDX;
+ poDS->adfGeoTransform[0] = atof(papszTokens[i + 1]);


line 463
- poDS->adfGeoTransform[3] = atof( papszTokens[j + 1] )
            - 0.5 * dfCellDY
            + poDS->nRasterYSize * dfCellDY;
+ poDS->adfGeoTransform[3] = atof( papszTokens[j + 1] )
            - dfCellDY
            + poDS->nRasterYSize * dfCellDY;


I've cross-checked the results with Arc/Info and SAGA GIS and it works 
fine now.

Other issues I'd like to see mentioned on the gdal_merge.py page 
(http://www.gdal.org/gdal_merge.html):
- if the output file is already existing, the behaviour of the module is 
indetermined as it tries to append to the file (?)
- the -ul_lr arguments reference the cell CENTERS

best regards,
Volker


Frank Warmerdam wrote:
> Volker Wichmann wrote:
>> Hi,
>>
>> I'm checking gdal_merge.py for generating subsets and mosaics from 
>> one or more input rasters. I found the following problem using esri 
>> ascii grids as input:
> ...
>> In case of the ascii, the file is resampled (and thus the values in 
>> the output subset differ from the original). This doesn't happen with 
>> a geotiff as input (see the "Copy" lines above).
>> It's also strange, that in both cases the reported UL and LR don't 
>> match the input coordinates and the extent of the output files (the 
>> latter match the coordinates passed with -ul_lr).
>>
>> I'm still using GDAL 1.4.2.0 but haven't found any major changes in 
>> trac regarding gdal_merge.py. It would be nice if somebody could try 
>> to reproduce this with GDAL 1.5 to see if any of the underlying 
>> functions have changed.
>
> Volker,
>
> I believe there have been some problems with "off by a half pixel" issues
> in the ESRI ASCII Grid driver since 1.4.2.  I would suggest upgrading to
> 1.5.1 if you can.   If the issue persists file a detailed ticket on it.
>
> Best regards,



More information about the gdal-dev mailing list