4

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")
2

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.

  • 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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.