Quantcast
Channel: Question and Answer » gdal
Viewing all articles
Browse latest Browse all 397

Rendering a geotiff block with gdal and gdk-pixbuf – Some flaws in the result

$
0
0

I currently try to render a geotiff file with GTKmmGDKmm (gdk-pixbuf). The file is a tiled geotiff with a block size of 256*256 and three rasterbands. The shortened gdalinfo output is:

Driver: GTiff/GeoTIFF
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 3528.0)
Upper Right ( 6189.0,    0.0)
Lower Right ( 6189.0, 3528.0)
Center      ( 3094.5, 1764.0)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue

I want to render the first block with this code:

std::unique_ptr<unsigned char[]> Dataset::getPixelData(int rasterBand)
{
    GDALRasterBand* band = data->GetRasterBand(rasterBand);
    int xSize = 0;
    int ySize = 0;

    band->GetBlockSize(&xSize, &ySize);
    if(xSize != 0|| ySize != 0) {
        int size = xSize*ySize; // GDALDatatype is GDT_Byte
        std::unique_ptr<unsigned char[]> ptr = std::unique_ptr<unsigned char[]>(
            new unsigned char[size]
        );
        band->ReadBlock(0,0,ptr.get());
        return ptr;
    } else {
        ...
    }
}

// Draw with pixbuf
void MapView::setPixelData(std::unique_ptr<unsigned char[]> pixel) 
{
    guchar* ptr = pixel.get();
    pixbuf = Gdk::Pixbuf::create_from_data(
        ptr,
        Gdk::Colorspace::COLORSPACE_RGB,
        false, // No alpha
        8, // 8 bit per sample
        256, // width
        256, // height
        256*3 // rowstride
    );
}

The basic drawing works, but the resulting image looks like this:

Result

The lower right section (with the word “Katzenbukel”) is the correct block I want to draw, but I cannot find out what is going wrong here. The lower left block (with the number 1729) is some part of the correct block, but it has to be on the right side. So there is some shifting effect in the image. Is there some offset in the data which I didn’t considered?

I also get the same result when reading other blocks of the image. Would appreciate some help here.


Viewing all articles
Browse latest Browse all 397

Trending Articles