[Gdal-dev] Another NetCDF driver bug fix

Joaquim Luis jluis at ualg.pt
Tue Oct 16 19:33:39 EDT 2007


Hi,

Although there is no track ticked assigned to it, it has been often 
referred here the problem of the
netCDF up-down flipping (and Surfer grids btw).

The problem is that SetProjection() in netcdfdataset.cpp assumes the Y 
coordinates vector is given
in descending order. So line nº 1087 (todays - 17-10-2007 svn version)

            poDS->adfGeoTransform[5] = (( pdfYCoord[ydim-1] -
                          pdfYCoord[0] ) /
                        ( poDS->nRasterYSize - 1 ));

and line 1098
                  poDS->adfGeoTransform[3] = pdfYCoord[0]
                      - (poDS->adfGeoTransform[5] / 2);

are expected to give a negative dy and the top left point.

However, the most common practice for Y orientation is increasing from 
bottom to top and not
the other way around.
To correct this problem one can add,  after line  1089
            if ( poDS->adfGeoTransform[5] > 0 )
             poDS->adfGeoTransform[5] *= -1;

which will work for both Y orientations

This corrects for the bad Upper Left when Y "grows up", but I here don't 
know a solution that works
for both Y orientation cases.

                  poDS->adfGeoTransform[3] = pdfYCoord[ydim-1]
                      - (poDS->adfGeoTransform[5] / 2);


A related note. With the risk of looking impatient (which I am) this 
netCDF driver bugs are trailing
for such a long time. Can't they be killed once for all?

Thanks

Joaquim Luis



More information about the Gdal-dev mailing list