Skip to content

Instantly share code, notes, and snippets.

@chadcooper
chadcooper / vue-get-object-size.py
Last active December 15, 2015 10:59
Getting the actual size of an object in Vue programmatically isn’t as easy as you’d think. You essentially have to get the BoundingBox of the object and work with that. So here we have a wind turbine object, and we have selected the pole and need to know (programmatically) how tall this pole really is. If you look at that z-value in the size pro…
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
@chadcooper
chadcooper / vue-load-terrain.py
Last active December 15, 2015 16:28
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):
def dd_to_dms(dd):
"""Convert a coordinate in decimal degrees to a tuple of (deg, min, sec)"""
is_positive = dd >= 0
dd = abs(dd)
minutes,seconds = divmod(dd*3600,60)
degrees,minutes = divmod(minutes,60)
degrees = degrees if is_positive else -degrees
return (degrees,minutes,seconds)
@chadcooper
chadcooper / raster-to-text-vue.py
Created April 2, 2013 00:29
Takes an input raster (Esri file geodatabase raster in this case) and translates it into a text file for import into Vue Infinite. See my gist called load-terrain.py, as it's related.
def translate_z(in_val, no_data, max_elev, min_elev):
""" Takes elevation Z values from raster and converts them to their
equivalent value on a scale of 0 to 1, where 0 is the minimum elevation
value of the raster dataset and 1 is the maximum. First add the min_z
absolute value to raster to bring lowest elevation value back up to zero.
"""
if in_val == no_data:
new_val = 0
else:
def raster_center(in_raster, gdb=""):
""" For given input raster, calculate center of bounding box and create a
point featureclass of the center
"""
raster = arcpy.Raster(in_raster)
center = arcpy.Point(raster.extent.XMin + (raster.extent.XMax - raster.extent.XMin)/2,
raster.extent.YMin + (raster.extent.YMax - raster.extent.YMin)/2)
if gdb:
gcenter = arcpy.PointGeometry(center, raster.spatialReference)
def get_raster_corners(in_raster):
"""Get XY coordinates of four corners of a raster as dictionary"""
r = arcpy.Raster(in_raster)
corners = ["lowerLeft", "lowerRight", "upperLeft", "upperRight"]
corner_dict = {}
for corner in corners:
x = getattr(r.extent, "%s" % corner).X
y = getattr(r.extent, "%s" % corner).Y
corner_dict[corner] = [x, y]
return corner_dict
def get_render_quality(in_quality):
"""
Takes a human-friendly render output quality and translates it into the
respective Vue setting.
"""
quality_dict = {"Preview" : VuePython.PRS_Preview,
"Final" : VuePython.PRS_Final}
if in_quality in quality_dict.keys():
@chadcooper
chadcooper / vue-move-sun.py
Created April 2, 2013 00:44
In Vue, the sun is just another object, so to move it, move it just like any other object.
# Position the sun
select_sun = SelectByName("Sun light")
sun = GetSelectedObjectByIndex(0)
# Sun position changes for each KOP
# Pitch and yaw are floats kept in a dict
sun_pitch = float(kop.get("SunPitch"))
sun_yaw = float(kop.get("SunYaw"))
sun.SetRotationAnglesV((sun_pitch, 0, sun_yaw), true)
Refresh()
@chadcooper
chadcooper / create-haversine-raster.py
Created April 2, 2013 00:54
Creates a haversine version of a raster elevation file for use in Vue Infinite.
class HaversineRaster(object):
"""Creates Haversine elevation raster for input into Vue
"""
def __init__(self, project_dir, project_name, raster):
self.project_dir = project_dir
self.project_name = project_name
self.in_raster = raster
self.props = v_utils.get_raster_props(raster)
self.hav_raster = self.create_haversine_raster()
@chadcooper
chadcooper / fetch-fips-codes.py
Created April 2, 2013 00:59
Fetches US FIPS codes for all states from a table on the EPA web site.
import BeautifulSoup as bs
import urllib2, re
def FetchFipsCodes( ):
""" Fetches a table of FIPS codes form a EPA webpage and tosses them
into a dictionary """
url = 'http://www.epa.gov/enviro/html/codes/state.html'
f = open('C:/temp/python/data/outputs/fips.csv', 'w')
# Fetch and parse the web page