Created
May 7, 2014 16:12
-
-
Save dtlanghoff/042c28f6d1c96d496391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import math | |
import sys | |
import gdal | |
import gdalconst | |
import numpy | |
from PIL import Image | |
CONTRAST = 10 | |
def main(demfile, imagefile): | |
# http://geoinformaticstutorial.blogspot.no/2012/09/reading-raster-data-with-python-and-gdal.html | |
dataset = gdal.Open(demfile, gdalconst.GA_ReadOnly) | |
width = dataset.RasterXSize | |
height = dataset.RasterYSize | |
band = dataset.GetRasterBand(1) | |
data = band.ReadAsArray(0, 0, width, height).astype(numpy.float) | |
im = Image.new('RGB', (width-1, height-1)) | |
pix = im.load() | |
for x in range(1, width): | |
if x % 50 == 0: | |
sys.stdout.write('\r[%s]' % ('-' * (x*60/width)).ljust(60)) | |
for y in range(1, height): | |
d = data[y, x] | |
h = int((d - data[y-1, x-1]) * CONTRAST + 128) if d != 0 else 0 | |
pix[x-1, y-1] = (h, h, h) | |
im.save(imagefile) | |
sys.stdout.write('\r[%s]\n' % ('-' * 60)) | |
if __name__ == '__main__': | |
if len(sys.argv) == 3: | |
main(sys.argv[1], sys.argv[2]) | |
else: | |
print 'usage: relieff.py input output' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment