Skip to content

Instantly share code, notes, and snippets.

@rumandcode
Created November 10, 2013 12:01
Show Gist options
  • Save rumandcode/7397387 to your computer and use it in GitHub Desktop.
Save rumandcode/7397387 to your computer and use it in GitHub Desktop.
Python script for rendering ASCII Grid format terrain data to a height map.
import argparse
parser = argparse.ArgumentParser(description='Python script for rendering ASCII Grid format terrain data to a height map.')
parser.add_argument('path-to-ascii-file', metavar='<path-to-ascii-file>', type=str,
help='path to the ASCII Grid format file')
parser.add_argument('output-path', metavar='<output-path>', type=str,
help='file path to write the output PNG to')
args = vars(parser.parse_args())
inputPath = args['path-to-ascii-file']
outputPath = args['output-path']
inputFile = open(inputPath, "r")
lines = inputFile.readlines()
if lines:
numColumns = lines[0].split(" ")[1]
numRows = lines[1].split(" ")[1]
longLatLocX = lines[2].split(" ")[1]
longLatLocY = lines[3].split(" ")[1]
resolution = lines[4].split(" ")[1]
for n in range(5, len(lines)):
elements = lines[n].split(" ")
for x in range(0, len(elements)):
value = elements[x]
lowestValue = min(value, lowestValue)
highestValue = max(value, highestValue)
else:
print("Could not read from file " + inputPath)
inputFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment