Contour

Summary

Creates a raster object for contour lines by joining points with the same value from a raster dataset. The contours are isolines created as rasters for visualization.

Discussion

For more information about how this function works, see the Contour raster function.

The referenced raster dataset for the raster object is temporary. To make it permanent, you can call the raster object's save method.

Syntax

Contour (raster, {adaptive_smoothing}, {contour_type}, {z_base}, {number_of_contours}, {contour_interval}, {nth_contour_line_in_bold}, {z_factor})
ParameterExplanationData Type
raster

The input raster.

Raster
adaptive_smoothing

The amount of smoothing to apply to the contour line. A lower value produces a contour line with more granularity and less smoothing, while a higher value produces a contour line with more smoothing that appears less jagged.

(The default value is 2.5)

Double
contour_type

The type of contour to be created.

  • contour lines Joins points of equal elevation to create a line representing constant elevation.
  • contour fill Fills the area between every contour line with the quantized elevation value.
  • smooth surface only Smooths the input elevation layer but does not produce contours.

(The default value is contour lines)

String
z_base

The base contour value. Contours are generated above and below this value as needed to cover the entire value range of the input raster.

A value of 0 often represents mean sea level, depending on the source elevation dataset.

(The default value is 0)

Double
number_of_contours

The number of contours to be generated. This dynamically adjusts the contour interval to fit the terrain in the display while maintaining standardized intervals such as 1, 5, 10, and so on.

(The default value is 0)

Integer
contour_interval

The difference in altitude between contour lines.

A small contour interval is used in relatively flat areas, while larger contour intervals are used in variable or mountainous terrain.

(The default value is 100)

Double
nth_contour_line_in_bold

The index contour, which is represented as a bold line.

(The default value is 5)

Integer
z_factor

The z-factor is a scaling factor used to convert the elevation values for the following purposes:

  • Convert the elevation units (such as meters or feet) to the horizontal coordinate units of the dataset, which may be feet, meters, or degrees.
  • Add vertical exaggeration for visual effect.

If the x,y units and z units are in the same units of measure, the z-factor should be set to 1. The z-values of the input surface are multiplied by the z-factor when calculating the final output surface.

(The default value is 1)

Double
Return Value
Data TypeExplanation
Raster

The output raster.

Code sample

Contour example 1

This example creates the contours for a given dataset.

from arcpy.ia import *
out_contour_raster = Contour("contour_input.tif", "", "smooth surface only", "", "", 150, 10, 2)
out_contour_raster.save("C:/arcpyexamples/outputs/contour_surface.tif")
Contour example 2

This example creates the contours for a given dataset.

# Import system modules
import arcpy
from arcpy.ia import *

# Set the analysis environments
arcpy.env.workspace = "C:/arcpyExamples/data"

# Set the local variables
in_raster = "contour_input.tif"

# Execute Contour function
out_contour_raster = Contour(in_raster, 3, "contour fill", 10, 20, 10, 3)

# Save the output
out_contour_raster.save("C:/arcpyExamples/outputs/contour_fill.tif")