diff --git a/CHANGELOG b/CHANGELOG index dbbe619ad..f1a702e17 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ For a complete change history, see the SVN log. Mapnik Trunk ------------ +- Support for NODATA values with grey and rgb images in GDAL plugin (#727) + - Print warning if invalid XML property names are used (#110) - Made XML property names use consistent dashes, never underscores (#644) diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index bb1fc0074..1583860e3 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -290,19 +290,69 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: processing rgb bands..." << std::endl; #endif + int hasNoData; + float nodata = red->GetNoDataValue(&hasNoData); + GDALColorTable *color_table = red->GetColorTable(); + + if (!alpha && hasNoData && !color_table) + { + // first read the data in and create an alpha channel from the nodata values + float *imageData = (float*)image.getBytes(); + red->RasterIO(GF_Read, x_off, y_off, width, height, + imageData, image.width(), image.height(), + GDT_Float32, 0, 0); + + int len = image.width() * image.height(); + + for (int i=0; i (&imageData[i]) = 0; + else + *reinterpret_cast (&imageData[i]) = 0xFFFFFFFF; + } + + } + red->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, image.width(),image.height(),GDT_Byte,4,4*image.width()); green->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 1, image.width(),image.height(),GDT_Byte,4,4*image.width()); blue->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 2, image.width(),image.height(),GDT_Byte,4,4*image.width()); + } else if (grey) { #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: processing gray band..." << std::endl; #endif - + int hasNoData; + float nodata = grey->GetNoDataValue(&hasNoData); + GDALColorTable *color_table = grey->GetColorTable(); + + if (hasNoData && !color_table) + { +#ifdef MAPNIK_DEBUG + std::clog << "\tno data value for layer: " << nodata << std::endl; +#endif + // first read the data in and create an alpha channel from the nodata values + float *imageData = (float*)image.getBytes(); + grey->RasterIO(GF_Read, x_off, y_off, width, height, + imageData, image.width(), image.height(), + GDT_Float32, 0, 0); + + int len = image.width() * image.height(); + + for (int i=0; i (&imageData[i]) = 0; + else + *reinterpret_cast (&imageData[i]) = 0xFFFFFFFF; + } + } + grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 1, @@ -310,9 +360,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 2, image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); - GDALColorTable *color_table = grey->GetColorTable(); if (color_table) { +#ifdef MAPNIK_DEBUG + std::clog << "GDAL Plugin: Loading colour table..." << std::endl; +#endif for (unsigned y = 0; y < image.height(); ++y) { unsigned int* row = image.getRow(y);