The SetExtent procedure method sets the view's extent around a four-cornered box. You may specify the corners of the box in the following coordinates: data (pixel), geographic, map, or Military Grid Reference System (MGRS).

Note: Only one coordinate keyword (DATA, GEO, MAP, MGRS) may be set.


; Launch the application
e = ENVI()
; Open a file
file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $
  SUBDIRECTORY = ['data'])
raster = e.OpenRaster(file)
; Display the data
view = e.GetView()
layer = view.CreateLayer(raster)
; Set the extent of the view in lon/lat
; (Since we're using a square extent, we only
; need to use two points)
extent = [-105.229817,39.996497,-105.224392,39.993153]
view.SetExtent, extent


ENVIView.SetExtent, Extent [, Keywords=value]



A coordinate array containing either two or four points.

If only two points are specified, they represent opposite corners of a rectangle.

If four points are specified, the extent encloses the four points. The points do not have to define a rectangle; they can define any four-sided polygon. Specify the points in this order: Lower-left corner of view, upper-left corner of view, upper-right corner of view, lower-right corner of view.

Extent must have the following syntax:

  • For geographical coordinates, the syntax is [lon1,lat1,lon2,lat2] for two points, or [lon1,lat1,lon2,lat2,lon3,lat3,lon4,lat4] for four points.
  • For map coordinates, the syntax is [x1,y1,x2,y2] for two points, or [x1,y1,x2,y2,x3,y3,x4,y4] for four points.
  • For data (pixel) coordinates, the syntax is [x1,y1,x2,y2] for two points, or [x1,y1,x2,y2,x3,y3,x4,y4] for four points, where x and y define pixel locations.

If you set the MGRS keyword, this argument is ignored.


Keywords are applied only during the initial creation of the object.


Set this keyword to an ENVIRasterLayer object that exists in the ENVIView. This indicates that Extent is expressed in pixel locations that correspond to the specified layer.


Set this keyword to a named variable that will contain any error message issued during execution of this routine. If no error occurs, the ERROR variable will be set to a null string (''). If an error occurs and the routine is a function, then the function result will be undefined.

When this keyword is not set and an error occurs, ENVI returns to the caller and execution halts. In this case, the error message is contained within !ERROR_STATE and can be caught using IDL's CATCH routine. See IDL Help for more information on !ERROR_STATE and CATCH.

See Manage Errors for more information on error handling in ENVI programming.


Set this keyword to specify that Extent is expressed in longitude and latitude. This is the default behavior if no coordinate keyword is set.


Set this keyword to specify that Extent is expressed in eastings and northings (for projected coordinate systems).


Set this keyword to an array of alphanumeric strings specifying Military Grid Reference System (MGRS) coordinates that define the extent. The array has the syntax [point1, point2] for two points, or [point1,point2,point3,point4] for four points. Each point string may contain between zero and five digits. Five digits correspond to one square meter of precision.

If you set this keyword, you do not need to specify Extent.

Version History



API Version


See Also

ENVIView, ENVIView::GetExtent