CONTOUR

Generate contours from a raster image


EnvironmentsPYTHON :: EASI :: MODELER
Quick linksDescription :: Parameters :: Parameter descriptions :: Return Value :: Details :: Examples :: Related

Back to top

Description


Creates a vector segment containing contour lines from a raster image, such as an elevation (DEM) image, given a specified contour interval. The contour value for each line is saved in either the z-coordinate of all vertices or in a separate attribute field.
Back to top

Parameters


contour(file, dbec, dbiw, dbsn, dbsd, contint, backval, fldnme)

Name Type Caption Length Value range
FILE * str Input file name 1 -    
DBEC * List[int] Input elevation channel 1 - 1  
DBIW List[int] Raster input window 0 - 4 Xoffset, Yoffset, Xsize, Ysize
DBSN * str Output segment name 1 - 8  
DBSD str Output segment description 0 - 64  
CONTINT * List[float] Contour interval and offset 1 - 2  
BACKVAL List[float] Background gray-level value 0 - 1  
FLDNME str Attribute field name 0 - 64 Default: ATTRIBUTE

* Required parameter
Back to top

Parameter descriptions

FILE

Specifies the name of the PCIDSK file from which the elevation image is read and to which the contour vector data is written.

DBEC

Specifies the image channel that contains raster or elevation (DEM) data. The input image channel can be any type; DEM data is usually a 16-bit signed integer.

DBIW

Specifies the raster window (Xoffset, Yoffset, Xsize, Ysize) that is read from the input image. If this parameter is not specified, the entire image is processed by default.

Xoffset, Yoffset define the upper-left starting pixel coordinates of the window. Xsize is the number of pixels that define the window width. Ysize is the number of lines that define the window height.

DBSN

Specifies a name (up to 8 characters) for the output vector segment. The default segment name is "CONTOUR".

DBSD

Optionally describes (in up to 64 characters) the contents or origins of the output data.

CONTINT

Specifies the interval between contour lines and an optional offset that is added to each contour value.

The contour interval must be a positive number.

The contour offset must be a value between zero and the specified interval value; the default is 0.0.

BACKVAL

Specifies the background elevation (NO DATA) value in the input raster or DEM elevation image.

FLDNME

Specifies the name of the double-precision field in which the contour value is stored. The field name is not case-sensitive.

If this parameter is specified as ATTRIBUTE or <field>, the contour value is saved in a double-precision field using the specified name.

If this parameter is specified as ZCOORD, the contour value is saved in the z-coordinates each vertex instead of in a field.

Available options are:
Back to top

Return Value

Returns: 

Type:  PCI_INT

If a new output vector segment is created, the LASC parameter is assigned the number of the new segment.

Back to top

Details

CONTOUR creates a set of elevation contours based on an input raster or DEM image.

CONTOUR creates a new vector segment that contains contour lines for a specified rectangular window (DBIW) of the input image channel (DBEC). The contour value of each line is assigned to either z-coordinates for vertices (FLDNME="zcoord") or to a specified double-precision field name (FLDNME).

The contour interval (CONTINT(1)) specifies the interval between the contour values for each line. An optional offset (CONTINT(2)) can be added to each contour value. The offset default is zero.

For example, assume that the input image is a 32-bit real image containing values from -0.4 to +0.7, and that CONTINT is set as follows:
CONTINT	=	0.2,0.1

This generates contours at -0.3, -0.1, 0.1, 0.3, 0.5 and 0.7.

The new vector segment is given a segment name (DBSN) and an optional description (DBSD). The vector segment contains only lines (no interior points).

Input pixels having the specified background gray-level value (BACKVAL) have an unknown elevation and are not used for generating contours. If the background gray-level value is not specified, all input pixels are assumed to have valid elevation values. The background gray-level value is typically set to zero, where the raster image is not rectangular and zeros are used around the border of the image.

The locations of the vertices for the contour lines are interpolated from the input image data.

The georeferencing segment from the PCIDSK file defines the units used for the vertices.

The vector segment created by CONTOUR can be used by interpolation programs (such as NNINT) to create an interpolated raster image, which should be similar (but not identical) to the original input image.

Back to top

Examples

Create elevation contours from the 16-bit signed integer DEM stored on image channel 10 of irvine.pix. The DEM pixel values measure elevation above sea level and range from 40 to 883 meters. The entire channel contains valid DEM data (that is, no background value). The contour value is saved in the field called "Elevation". A new vector segment is created on irvine.pix to contain the elevation contours. Use the IVV program to transfer the contours to the display.

The contour interval is 100 with no offset; therefore, contours are created at 100, 200, 300, 400, 500, 600, 700, and 800 meters.

from pci.contour import contour

file	=	'irivne.pix'
dbec	=	[10]
dbiw	=	[]
dbsn	=	'CONTOURS'
dbsd	=	'100 metre contour interval'
contint	=	[100]
backval	=	[]
fldnme	=	'Elevation'

lasc = contour( file, dbec, dbiw, dbsn, dbsd, \
                contint, backval, fldnme )

If the contour interval is 250 with an offset of 125, contours are created at 125, 375, 625, and 875 meters.

from pci.contour import contour

file	=	'irvine.pix'
dbec	=	[10]
dbiw	=	[]
dbsn	=	'CONTOURS'
dbsd	=	'250 metre contours with 125 offset'
contint =	[250,125]
backval	=	[]
fldnme	=	'Elevation'

lasc =  contour( file, dbec, dbiw, dbsn, dbsd, \
                 contint, backval, fldnme )

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.