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.

I've written a program in Python with GDAL bindings that generates a single band georeferenced GeoTIFF as output. From there I use the GDAL commandline tool gdaldem to colorize that image to highlight certain classes of pixels. I'd like to also lay it on top of a basemap DEM as final output but I need to do this procedurally in my program as opposed to load both layers into a GIS tool and blend from there.

Are there any GDAL command line utilities I can use to blend two GeoTIFFs together and output a pretty png?

Here's a specific example with some random datasets:

  DEM                                  Pixels

  Pixels + DEM Blended (This is what I want to do with command line tools)

Update:

I ended up using the blend function from PIL like this:

basemap_image = Image.open('basemap.png').convert('RGBA')
overlay_image = Image.open('overlay.png').convert('RGBA')
combined = Image.blend(basemap_image, overlay_image, 0.8)
combined.save("out.png")
share|improve this question

2 Answers 2

up vote 1 down vote accepted

You're going to want to use the Python imaging library. PIL.

You will want to load up the first image of the DEM and make sure its in an RGBA format.

from PIL import Image

dem_image = Image.open('dem.png').convert('RGBA')
color_pixels = Image.open('pixels.png').convert('RGBA')

combined = dem_image.paste(color_pixels, (0,0), color_pixels)

Might need to make sure your color_pixels image has an alpha layer as that's what is used for paste. Otherwise you will have to go through it and create a transparency layer in color_pixels by iterating over the values and setting white to an alpha channel.

Hope that helps, or at least gets you started.

share|improve this answer
    
Yep, this is great! Thanks for the help. –  Rich Mar 27 '12 at 5:52
    
FYI, the blend function turned out to be the most helpful for what I was trying to do. –  Rich Mar 29 '12 at 6:27

Sorry, I'm not a GDAL expert but this can help you: http://invisibleroads.com/tutorials/gdal-raster-merge.html

GDAL have commands to merge, wrap, ... and many more things to do with geo-images.

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.