Skip to content

Instantly share code, notes, and snippets.

@perrygeo
Last active April 29, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perrygeo/07ce04fe886d1c8090ab1b22d7579396 to your computer and use it in GitHub Desktop.
Save perrygeo/07ce04fe886d1c8090ab1b22d7579396 to your computer and use it in GitHub Desktop.
GDAL IO Error on Decimated reads on alpha band
#include "gdal.h"
#include "cpl_conv.h" /* for CPLMalloc() */
/*
* compile with
* gcc `gdal-config --cflags` `gdal-config --libs` -o test test.c
*
*/
/*
* For test dataset `alpha.tif`
* https://github.com/mapbox/rasterio/raw/issue-679/tests/data/alpha.tif
*
*/
/*
* Results w/ GDAL 2.x
*
Reading band 1 into 735x735
completed
Reading band 1 into 734x734
completed
Reading band 2 into 735x735
completed
Reading band 2 into 734x734
completed
Reading band 3 into 735x735
completed
Reading band 3 into 734x734
completed
Reading band 4 into 735x735
completed
Reading band 4 into 734x734
ERROR 1: IReadBlock failed at X offset 0, Y offset 0
completed
*/
int main()
{
GDALDatasetH hDataset;
GDALAllRegister();
GDALDriverH hDriver;
GDALRasterBandH hBand;
double adfGeoTransform[6];
char *pafScanline;
int bandnum;
int outX;
int outY;
int nXSize;
int nYSize;
hDataset = GDALOpen( "alpha.tif", GA_ReadOnly );
if( hDataset == NULL ) {
exit(1);
}
for ( bandnum = 1; bandnum <= 4; bandnum++ ) {
hBand = GDALGetRasterBand( hDataset, bandnum );
nXSize = GDALGetRasterBandXSize( hBand );
nYSize = GDALGetRasterBandYSize( hBand );
outX = 735;
outY = 735;
pafScanline = (char *) CPLMalloc(sizeof(char) * outX * outY);
printf("Reading band %d into %dx%d\n", bandnum, outX, outY);
GDALRasterIO( hBand, GF_Read, 0, 0, nXSize, nYSize,
pafScanline, outX, outY, GDT_Byte,
0, 0 );
printf(" completed\n");
outX = 734;
outY = 734;
pafScanline = (char *) CPLMalloc(sizeof(char) * outX * outY);
printf("Reading band %d into %dx%d\n", bandnum, outX, outY);
GDALRasterIO( hBand, GF_Read, 0, 0, nXSize, nYSize,
pafScanline, outX, outY, GDT_Byte,
0, 0 );
printf(" completed\n");
}
}
@perrygeo
Copy link
Author

Dataset info

$ gdalinfo alpha.tif
Driver: GTiff/GeoTIFF
Files: alpha.tif
Size is 1223, 1223
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
Origin = (19474931.814599998295307,-4794130.414049999788404)
Pixel Size = (3.999975306625407,-3.999975314800181)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=JPEG
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (19474931.815,-4794130.414) (174d56'46.64"E, 39d30'14.55"S)
Lower Left  (19474931.815,-4799022.384) (174d56'46.64"E, 39d32'16.58"S)
Upper Right (19479823.784,-4794130.414) (174d59'24.84"E, 39d30'14.55"S)
Lower Right (19479823.784,-4799022.384) (174d59'24.84"E, 39d32'16.58"S)
Center      (19477377.799,-4796576.399) (174d58' 5.74"E, 39d31'15.57"S)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment