"""****************************************************************************
Name: Create Terrain from TIN
Description: This script demonstrates how to create a terrain dataset using
features extracted from a TIN. It is particularly useful in
situations where the source data used in the TIN is not available,
and the amount of data stored in the TIN proves to be too large
for the TIN. The terrain's scalability will allow improved
display performance and faster analysis. The script is designed
to work as a script tool with 5 input arguments.
****************************************************************************"""
import arcpy
tin = arcpy.GetParameterAsText(0)
gdbLocation = arcpy.GetParameterAsText(1)
gdbName = arcpy.GetParameterAsText(2)
fdName = arcpy.GetParameterAsText(3)
terrainName = arcpy.GetParameterAsText(4)
try:
arcpy.management.CreateFileGDB(gdbLocation, gdbName)
gdb = '{0}/{1}'.format(gdbLocation, gdbName)
SR = arcpy.Describe(tin).spatialReference
arcpy.management.CreateFeatureDataset(gdb, fdName, SR)
fd = '{0}/{1}'.format(gdb, fdName)
arcpy.AddMessage("Exporting TIN footprint to define terrain boundary...")
boundary = "{0}/boundary".format(fd)
arcpy.ddd.TinDomain(tin, tinDomain, 'POLYGON')
arcpy.AddMessage("Exporting TIN breaklines...")
breaklines = "{0}/breaklines".format(fd)
arcpy.ddd.TinLine(tin, breaklines, "Code")
arcpy.AddMessage("Exporting TIN nodes...")
masspoints = "{0}/masspoints".format(fd)
arcpy.ddd.TinNode(sourceTIN, TIN_nodes)
arcpy.AddMessage("Creating terrain dataset...")
terrain = "terrain_from_tin"
arcpy.ddd.CreateTerrain(fd, terrainName, 10, 50000, "",
"WINDOWSIZE", "ZMEAN", "NONE", 1)
arcpy.AddMessage("Adding terrain pyramid levels...")
terrain = "{0}/{1}".format(fd, terrainName)
pyramids = ["20 5000", "25 10000", "35 25000", "50 50000"]
arcpy.ddd.AddTerrainPyramidLevel(terrain, "", pyramids)
arcpy.AddMessage("Adding features to terrain...")
inFeatures = "{0} Shape softclip 1 0 10 true false boundary_embed <None> "\
"false; {1} Shape masspoints 1 0 50 true false points_embed "\
"<None> false; {2} Shape softline 1 0 25 false false lines_embed "\
"<None> false".format(boundary, masspoints, breaklines)
arcpy.ddd.AddFeatureClassToTerrain(terrain, inFeatures)
arcpy.AddMessage("Building terrain...")
arcpy.ddd.BuildTerrain(terrain, "NO_UPDATE_EXTENT")
arcpy.GetMessages()
except arcpy.ExecuteError:
print(arcpy.GetMessages())
except Exception as err:
print(err)