Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When using the ArcObject RasterCursor (see snippet below), how do I get the absolute row / column of the current pixel value?

IRasterCursor rasterCursor = raster.CreateCursorEx(null);

do
{
    IPixelBlock3 pixelblock = rasterCursor.PixelBlock as IPixelBlock3;

    Array pixels = (Array)pixelblock.PixelData[rasterBandIndex];

    for (int i = 0; i < pixelblock.Width; i++)
    {
        for (int j = 0; j < pixelblock.Height; j++)
        {
            // How to get absolute row / column of this pixelvalue
            dynamic pixelValue = pixels.GetValue(i, j);
        }
    }
}
while (rasterCursor.Next());
share|improve this question

RasterCursor.TopLeft can be used to do this. Don't ask me why it is returning double though.

IRasterCursor rasterCursor = raster.CreateCursorEx(null);

do
{
    IPixelBlock3 pixelblock = rasterCursor.PixelBlock as IPixelBlock3;

    Array pixels = (Array)pixelblock.PixelData[rasterBandIndex];

    double x = rasterCursor.TopLeft.X;
    double y = rasterCursor.TopLeft.Y;

    for (int i = 0; i < pixelblock.Width; i++)
    {
        for (int j = 0; j < pixelblock.Height; j++)
        {
            // This is pixel (int)x + i, (int)y + j of the rasterdataset
            dynamic pixelValue = pixels.GetValue(i, j);
         }
    }
}
while (rasterCursor.Next());
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.