Skip to content

Instantly share code, notes, and snippets.

@K240-zz
Created February 1, 2012 22:54
Show Gist options
  • Select an option

  • Save K240-zz/1719974 to your computer and use it in GitHub Desktop.

Select an option

Save K240-zz/1719974 to your computer and use it in GitHub Desktop.
Import HGT Python SOP.
from struct import unpack, calcsize
def loadHGT( filename, row, row_length ):
data = []
try:
f = open( filename, 'rb' )
format = '!H'
f.seek( row * row_length * calcsize(format) )
for i in xrange(row_length):
data.append( unpack(format, f.read(calcsize(format)))[0] )
f.close()
except:
pass
return data
filename = hou.pwd().parm("filename").evalAsString()
w = hou.pwd().parm("width").evalAsFloat()
# Row Length probably 1201 or 3601
row_length = hou.pwd().parm("row_length").evalAsInt()
hs = hou.pwd().parm("height_scale").evalAsFloat()
skip = hou.pwd().parm("skip").evalAsInt()
if (w*row_length*skip) != 0:
geo = hou.pwd().geometry()
ofs = w / row_length
z = -w / 2.0
for row in xrange(0, row_length, skip):
# Can't wait cooking? then press ESC:
if hou.updateProgressAndCheckForInterrupt():
break
rdata = loadHGT( filename, row, row_length )
x = -w / 2.0
for i in xrange(0, len(rdata)-1, skip):
p = geo.createPoint()
p.setPosition( (x + ofs * i, float(rdata[i]) * hs, z + ofs * row) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment