1

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 geo-referenced location of a pixels value within the pixel itself (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)
  • the bottom-right corner of RasterData[3][3] has a geo-referenced position of (4.0, 4.0)
  • the center of RasterData[0][0] has a geo-referenced position of (0.5, 0.5)

This part I believe I understand well enough.

However, I do not understand how to determine the (geo-referenced) location of a pixels data within the pixel itself, nor do I understand whether PixelIsPoint / PixelIsArea affects the location of the pixel corners, or the location of a pixels data within the pixel itself.

For example, I'm not entirely certain whether this is the correct way to create a vertex from this dataset:

// loop pixel_y 0 -> height (integer)
// loop pixel_x 0 -> width  (integer)
vertex.x = GeoTransform[0] + GeoTransform[1] * pixel_x + GeoTransform[2] * pixel_y;
vertex.y = GeoTransform[3] + GeoTransform[4] * pixel_x + GeoTransform[5] * pixel_y;
vertex.z = RasterData[y][x];

The method above assumes the value of RasterData[y][x] is geo-referenced at the top-left corner point of the pixel -- this is where my doubt begins.

So my question is:
How do I determine the correct geo-referenced position of a given pixel value RasterData[y][x] when interpreting the data under PixelIsPoint versus PixelIsArea?

IE: I want to take RasterData[y][x] and GeoTransform and generate (X,Y,Z) vertex positions where:

  • The X coordinate is the appropriate geo-referenced position for RasterData[y][x]
  • The Y coordinate is the appropriate geo-referenced position for RasterData[y][x]
  • The Z coordinate is the height value contained in RasterData[y][x]
5
  • Welcome to GIS SE. As a new user, please take the Tour which emphasizes the importance of asking One question per Question. Please edit your question to ask one question.
    – Vince
    Commented Oct 8, 2019 at 18:31
  • @Vince I have reformulated the questions into a single, hopefully-clearer question. Thank you!
    – Naxos
    Commented Oct 8, 2019 at 19:35
  • You've got a TL/DR issue here. Six actual question marks in two labeled questions isn't helping. This topic is rather fundamental to the definition of rasters, but touches on the imagery equivalent of physics' wave/particle duality -- Is a pixel a point or an area? Since the answer is both, the measures of image extents share that awkwardness, sometimes UL-Center -> LR Center, and sometimes UL Corner to LR Corner (or even LL Corner to UR Corner). Given that you have empirical tool available, you can answer how GDAL handles this without asking others for their interpretation.
    – Vince
    Commented Oct 8, 2019 at 19:43
  • @Vince Sorry about that, I've got it down to one '?' now! What empirical tool are you referring to? I suppose an alternate formulation of the original question might be: Where within the pixel does a point value refer, and where within the pixel is center of the area?
    – Naxos
    Commented Oct 8, 2019 at 19:47
  • The pixel doesn't refer to any one point -- it's a pixel, so it refers to all of them (which makes a shift of up to 1/2 pixel size "safe"). If you choose to use center-center (also at the 1/2 pixel threshold), it's not likely someone will have a convincing reason that it's wrong.
    – Vince
    Commented Oct 9, 2019 at 0:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.