Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Last active December 15, 2015 16:28
Show Gist options
  • Save chadcooper/5288959 to your computer and use it in GitHub Desktop.
Save chadcooper/5288959 to your computer and use it in GitHub Desktop.
Loads a text file of elevation values derived from USGS NED 1/9 arc-second data into Vue Infinite.
terr_width = 3576
terr_height = 4440
terr_min_elev = -6.0801
terr_max_elev = 28.20632
terr_cell_res = 3.09129
terr_z_elev = -6.083407
terr_name = "NC_Kitty_Hawk_DEV"
def get_object_size(vue_object):
""" Takes a input Vue object, gets it's bounding box, then does the
math to get the XYZ size of the object. Returns a X,Y,Z tuple of
the object size.
"""
bounding_box = vue_object.GetBoundingBox()
bb_min = bounding_box.GetMin()
bb_max = bounding_box.GetMax()
# Build our tuple of object XYZ size
object_size = (bb_max[0] - bb_min[0], bb_max[1] - bb_min[1],
bb_max[2] - bb_min[2])
return object_size
# Add terrain to scene
DeselectAll()
terr = AddTerrain(terr_width, terr_height, VuePython.VUEChild.TT_StandardTerrain,
false, false)
b_object = GetSelectedObjectByIndex(0)
terrain_obj = b_object.ToTerrain()
terrain_obj.SetName(terr_name)
Refresh()
terrain_obj.SetTerrainResolution(terr_width, terr_height)
# Determine longest side of terrain raster. Set w_or_h to terr_width by default
w_or_h = terr_width
if terr_height > terr_width:
w_or_h = terr_height
# Slurp elevation text file into memory
elev_file = r"C:\Users\Projects\vue\elevation.txt"
elev_file = open(elev_file, "r")
altitudes = []
while 1:
line = elev_file.readline()
if not(line):
break
bits = line.split(",")
alt = []
for x in bits:
alt.append(float(x))
altitudes.append(alt)
# Push our elevation data into the terrain object
terrain_obj.SetTerrainAltitudes(altitudes)
# Calc x-y scale factors
x_scale = (w_or_h * terr_cell_res)/1000
y_scale = (w_or_h * terr_cell_res)/1000
# Get z-size of terrain as it is now in Vue after replacement above
# -- before it gets scaled
terr_bbox = terrain_obj.GetBoundingBox()
terr_z_size = terr_bbox.GetMax()[2] - terr_bbox.GetMin()[2]
actual_terr_z_size = abs(terr_max_elev - terr_min_elev) # Size we want terrain to be in Z
z_scale = actual_terr_z_size/terr_z_size
# Resize terrain based on calc'd scale factors
b_object.ResizeAxis(x_scale, y_scale, z_scale, true)
terr_bbox = terrain_obj.GetBoundingBox()
terr_z_size = terr_bbox.GetMax()[2] - terr_bbox.GetMin()[2]
# Set z-Position for terrain
b_object.SetPosition(0, 0, terr_z_elev)
# Done
DeselectAll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment