Terrain To Raster (3D Analyst)
Summary
Converts a terrain dataset into a raster.
Usage
-
The resolution parameter indicates which pyramid level of the terrain to use for conversion. Pyramid levels are defined using the z-tolerance or window-size pyramid types. For more information on terrain pyramids, see Terrain Pyramids.
-
To extract a subset of the terrain, define the extent using the geoprocessing environment settings.
-
The available interpolation options are LINEAR and NATURAL_NEIGHBORS. These are TIN-based methods applied through the triangulated terrain surface. The linear option finds the triangle encompassing each cell center and applies a weighted average of the triangle's nodes to interpolate a value. The natural neighbors option uses area-based weights on Voronoi neighbors.
-
The output raster may be file based or created as a raster dataset in a geodatabase. A file based raster format is determined by the extension given to the raster. For example, use of the extensions .img and .tif will produce IMAGINE or TIFF files. If the raster does not include a file extension, an Esri GRID will be produced.
Syntax
Parameter | Explanation | Data Type |
in_terrain |
The input terrain dataset. | Terrain Layer |
out_raster |
The location and name of the output raster. When storing a raster dataset in a geodatabase or in a folder such as an Esri Grid, no file extension should be added to the name of the raster dataset. A file extension can be provided to define the raster's format when storing it in a folder:
If the raster is stored as a TIFF file or in a geodatabase, its raster compression type and quality can be specified using geoprocessing environment settings. | Raster Dataset |
data_type (Optional) |
The data type of the output raster can be defined by the following keywords:
| String |
method (Optional) |
Choose an interpolation method. By default, cell values are calculated using the LINEAR method.
| String |
sample_distance sampling_method distance (Optional) |
The sampling method and distance used to define the cell size of the output raster.
| String |
pyramid_level_resolution (Optional) |
The z-tolerance or window-size resolution of the terrain pyramid level that will be used by this tool. The default is 0, or full resolution. | Double |
Code Sample
The following sample demonstrates the use of this tool in the Python window:
import arcpy from arcpy import env arcpy.CheckOutExtension("3D") env.workspace = "C:/data" arcpy.TerrainToRaster_3d("sample.gdb/featuredataset/terrain", "terrain.img", "INT", "LINEAR", "CELLSIZE 10", 2.5)
The following sample demonstrates the use of this tool in a stand-alone Python script:
'''********************************************************************* Name: TerrainToRaster Example Description: This script demonstrates how to use the TerrainToRaster tool. **********************************************************************''' # Import system modules import arcpy from arcpy import env import exceptions, sys, traceback try: arcpy.CheckOutExtension("3D") # Set environment setting env.workspace = "C:/data" # Set Local Variables terrain = "sample.gdb/featuredataset/terrain" bitType = "INT" method = "LINEAR" sampling = "CELLSIZE 10" pyrLvl = 2.5 outRas = arcpy.CreateUniqueName("terrain_level.img") #Execute TerrainToRaster arcpy.ddd.TerrainToRaster(terrain, outRas, bitType, method, sampling, pyrLvl) arcpy.CheckInExtension("3D") except arcpy.ExecuteError: print arcpy.GetMessages() except: # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate error information into message string pymsg = 'PYTHON ERRORS:\nTraceback info:\n{0}\nError Info:\n{1}'\ .format(tbinfo, str(sys.exc_info()[1])) msgs = 'ArcPy ERRORS:\n {0}\n'.format(arcpy.GetMessages(2)) # Return python error messages for script tool or Python Window arcpy.AddError(pymsg) arcpy.AddError(msgs)