I'm trying to understand how to interpret the position of pixel data within a GDAL raster, specifically as it applies to files containing height data. I'm create Triangular Regular Network (TRN) for terrain from various GDAL sources and need to generate the terrain as precisely as possible.
I've read the follow sources several times, but I have failed to understand whether they answer my questions:
Is there a standard for the coordinates of pixels in georeferenced rasters ?
Seeking tool to generate Mesh from DTM?
Does a value in srtm dem file refer to the center or corner of a cell?
The GDAL documentation has this to say about the GeoTransform:
Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
In case of north up images, the GT(2) and GT(4) coefficients are zero, and the GT(1) is pixel width, and GT(5) is pixel height. The (GT(0),GT(3)) position is the top left corner of the top left pixel of the raster.
Note that the pixel/line coordinates in the above are from (0.0,0.0) at the top left corner of the top left pixel to (width_in_pixels,height_in_pixels) at the bottom right corner of the bottom right pixel. The pixel/line location of the center of the top left pixel would therefore be (0.5,0.5).
I understand the last paragraph in the quote above. However, my confusion begins when trying to understand the position of the data value in the cell (height in my case) and the interaction of PixelIsPoint vs PixelIsArea.
So, by way example, if we consider a very simple raster:
float RasterData[4][4] = {
{ 1.0f, 2.0f, 1.0f, 3.0f },
{ 1.5f, 1.5f, 2.0f, 2.5f },
{ 2.0f, 2.0f, 2.5f, 2.0f },
{ 1.5f, 2.0f, 2.0f, 1.5f }
};
float GeoTransform[6] = {
0.0f, // X origin
1.0f, // Xaxis.x of transform
0.0f, // Xaxis.y of transform
0.0f, // Y origin
0.0f, // Yaxis.x of transform
1.0f // Yaxis.y of transform
};
By the GDAL documentation, the top-left corner of RasterData[0][0]
has a geo-referenced position of (0.0, 0,0) and the bottom-right corner of RasterData[3][3]
has a geo-referenced position of (4.0, 4.0).
First question:
Does the interpretation of PixelIsPoint / PixelIsArea affect this interpretation of the corner position of the raster? And if so, in what manner? IE: Could the top-left corner of RasterData[0][0]
possibly be (-0.5,-0.5) or (0.5, 0.5)?
Second question:
Given that RasterData[0][0] == 1.0f
and we interpret that as a height value, does that value correspond most appropriately to the top-left corner position of the pixel, or to the center of the pixel? IE: would a vertex generated from RasterData[0][0]
would be most appropriate at (0.0, 0.0, 1.0) or (0.5, 0.5, 1.0)? How does the interpretation of PixelIsPoint / PixelIsArea affect this?