Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

When you run gdal2tiles, by default it sets pixels outside your map area to black-transparent. I would like to set them to white opaque. Looking at the documentation... http://www.gdal.org/gdal2tiles.html

it looks like the setting --srcnodata=NODATA might do it, but it doesnt explain what the allowed values for the 'NODATA' argument are. I have made various attempts but they had no effect e.g...

gdal2tiles -r near --srcnodata=255 -z12-12 in.tiff outDirectory

share|improve this question

1 Answer 1

up vote 0 down vote accepted

gdal2tiles doesn't replace one set of nodata vales with another, it only allows you to override or set the nodata values for the source image. It reads the nodata values from the source image, if it has any, but the --srcnodata parameter overrides it. It takes a comma-separated list of values, one for each source band, but if you supply fewer values than there are bands, it just repeats the values you gave it. So your parameters should replicate 255 for however many bands there are.

But because it doesn't do anything clever with the values you provide, if the source image has 0,0,0 as its nodata values, you're merely defining any pixels of 255,255,255 as nodata and your black pixels will be just that.

You will need to run your image through gdalwarp first, using the -srcnodata and -dstnodata parameters.

But what you really seem to be after is nothing to do with the conversion of the data, but the drawing of it, and that is really up to whichever application you have that does your rendering. After all, nodata isn't a colour, it's a special value and its up to you (or your software) to decide what to do with that special value.

share|improve this answer
    
thanks @MerseyViking, I'm completely confused about the 'nodata' concept. Can you please explain what you mean by "if the source image has 0,0,0 as its nodata values, you're merely defining any pixels of 255,255,255 as nodata and your black pixels will be just that." –  spiderplant0 Jan 20 '12 at 19:32
    
I wasnt quite sure what you meant by "But what you really seem to be after is nothing to do with the c.." The stage after the gdal2tiles is spacial low-pass filtering and when I run filtering, the black-transparent pixels generated by gdal2tiles are producing artefacts. The filter doesnt have a way to tell it about special values, so I thought the best idea was to just replace them (I suggested white-opaque as this filters well). –  spiderplant0 Jan 20 '12 at 19:38
    
The nodata value is just a special marker in the image that tells software not to process it, render it, or do anything with it at all. The actual numbers of the nodata value are arbitrary. For instance, in floating-point imagery, -9999 is a common nodata value and it is set in the image's metadata. Then when an application comes to process that image, it will ignore any pixel it finds with that value. For 3-channel colour images (usually red, green, blue) there is often a special case where all three channels of a pixel have to match their nodata values before they can be ignored. –  MerseyViking Jan 24 '12 at 10:44
    
I would suggest you run your spatial filter on the untiled data, and then run gdal2tiles because if you execute your filter on the tiled data, the filter won't be able to get any data from the neighbouring tiles and so you'll probably end up with artefacts around the edges of each tile. If your filter is including nodata pixels in its calculations, then either your filter isn't honouring the nodata settings (an image-processing program like Gimp for instance), or the nodata metadata value hasn't been set, in which case you'll need to use gdal_translate with the --a_nodata parameter. –  MerseyViking Jan 24 '12 at 10:51
    
Thanks for the explanation @MerseyViking. I'll try what you suggest. (By the way, one of the reasons I'm filtering the tiles rather than the complete image is that the filter cant cope with such a large image (eg map of all of England at google zoom12) - I avoid artefacts at the tile edges by filtering overlapping batches of tiles (the logic isnt as hard as it sounds). –  spiderplant0 Jan 25 '12 at 20:37

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.