[Gdal-dev] how is yllcorner determined and why

Janeen janeen at splash.princeton.edu
Mon Dec 18 12:23:33 EST 2006


Hello All,

I thought I would post my solution for the issues that I found when 
using the gdal_translate utility to convert from netCdf format files to 
the AAIGrid format.  I made a few code changes in the AAIGrid format 
driver and recompiled the source code.  I had 2 problems that seemed to 
me, were not being handled correctly or at all.  So here is how I 
resolved it in the code.  This is a very limited solution for my very 
narrow case.  If anyone cares to comment, I would be interested, since I 
am very new to GDAL.

In the file:          /frmts/aaigrid/aaigriddataset.cpp

I changed the code that outputs  the AAIGRID header information to:
        sprintf( szHeader,
                 "ncols        %d\n"
                 "nrows        %d\n"
                 "xllcorner    %.12f\n"
                 "yllcorner    %.12f\n"
                 "dx           %.12f\n"
                 "dy           %.12f\n",
                 nXSize, nYSize,
                 adfGeoTransform[0],
                 adfGeoTransform[3],    /* changed */ 
                 ( adfGeoTransform[1] * nXSize + 1)/ nXSize,    /* 
changed */
                 ( adfGeoTransform[5] * nYSize + 1)/ nYSize );    
/*changed */

This gives me what I believe to be the correct values for the yllcorner, 
dx and dy, based on my .nc files.  Then since my netCDF files are 
flipped, with the origin at the upper left I changed the for loop that 
writes out the lines of data to write the lines in reverse:
   for( iLine = (nYSize - 1); eErr == CE_None && iLine >= 0; iLine-- )

and for the outputting progress data correctly based on the above:
           !pfnProgress((nYSize - iLine + 1) /
                        ((double) nYSize), NULL, pProgressData) )

Cheers!

Janeen




Janeen wrote:
> All,
>
> I've a correction to my original post.  I discovered that in trying to 
> figure out how the value for yllcorner is calculated by 
> gdal_translate, I was using the dy value NOT the dx value, as the line 
> of code states.  See corrections within mail.
>
> But that leaves me with 2 new questions:
>
>   Why is the dx value used to calculate the yllcorner in the Ascii Grid?
>   And what in the original .nc file is the yllcorner  = -269 related to?
>
> Any light shed on this would be appreciated.
>
> Janeen
>
> Janeen wrote:
>> Hello All,
>>
>> I've just tried the gdal_translate utility on a NetCDF file, 
>> converting it to the AAIGrid format.  I'm new to the world of GIS and 
>> NetCDF also.  So in using the utility, I want to be sure that I 
>> understand how all the data from  the  .nc file  makes it over to the 
>> ascii file.
>>
>> I can't quite figure out how the yllcorner value being reported is 
>> calculated, and why it is transformed the way it is.  I've looked at 
>> the code and gotten as far as this line in aaigriddataset.cpp:
>>
>>   adfGeoTransform[3]- nYSize * adfGeoTransform[1]
>>
>> I can't quite get what the variable adfGeoTransform[3] represents 
>> from the original .nc file.  The part of the equation:
>>    nYSize * adfGeoTransform[1] I understand where those values  come 
>> from in my sample file (i.e. 180 *  0.994444444444  = 179 ).
>  in my example this should be 180 * 0.997222222222 = 179.5
>
>> Given that yllcorner is being reported as -269, that means that the 
>> value for adfGeoTransform[3] would be -90.   But what does that value 
>> represent in my original netCDF file given the info below?
>>
>
> the actual value for adfGeoTransform[3] becomes -89.5  which is the 
> southern most latitude value in the .nc file.
>
>
>> If anyone can give me a description of what is going on here, I would 
>> appreciate it.  Below is header  and gdalinfo.
>>
>> Janeen
>>
>>
>> Here is the gdal header info from my converted .nc file:
>>
>>   cols        360
>>   nrows        180
>>   xllcorner    0.500000000000
>>   yllcorner    -269.000000000000
>>   dx           0.997222222222
>>   dy           0.994444444444
>>   NODATA_value -10000000000
>>
>> Here is (relevant) gdalinfo from my .nc file
>>   Driver: netCDF/Network Common Data Format
>>   Size is 360, 180
>>   Coordinate System is `'
>>   Origin = (0.500000,-89.500000)
>>   Pixel Size = (0.99722222,0.99444444)
>>   Corner Coordinates:
>>   Upper Left  (   0.5000000, -89.5000000)
>>   Lower Left  (   0.5000000,  89.5000000)
>>   Upper Right (     359.500,     -89.500)
>>   Lower Right (     359.500,      89.500)
>>   Center      ( 180.0000000,   0.0000000)
>>
>>
>>
>> _______________________________________________
>> Gdal-dev mailing list
>> Gdal-dev at lists.maptools.org
>> http://lists.maptools.org/mailman/listinfo/gdal-dev
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list