X

NV5 Geospatial Blog

Each month, NV5 Geospatial posts new blog content across a variety of categories. Browse our latest posts below to learn about important geospatial information or use the search bar to find a specific topic or author. Stay informed of the latest blog posts, events, and technologies by joining our email list!



Using ENVI and IDL Agents with Your Own API Keys

Using ENVI and IDL Agents with Your Own API Keys

6/22/2026

Earlier this year, we introduced the ENVI® Agent and IDL® Agent to bring intelligent, AI-driven automation to your geospatial and data science workflows. If you missed the launch, you can catch up on the full breakdown by watching our release webinar. Both agents are built upon GitHub Copilot, a powerful AI orchestration... Read More >

What We're Looking Forward to at Esri UC 2026

What We're Looking Forward to at Esri UC 2026

6/16/2026

Every year, the Esri User Conference brings together thousands of geospatial professionals to explore new technologies, share ideas, and learn how organizations are solving complex challenges with GIS. For many members of the NV5 team, attending Esri UC is an annual tradition. Some have attended for more than 15 years. Others will be... Read More >

New ENVI Agent, IDL Agent, and GeoAgent Quick Guides

New ENVI Agent, IDL Agent, and GeoAgent Quick Guides

6/9/2026

The recent release of ENVI® Agent, IDL® Agent, and GeoAgent™ revolutionize how users interact with geospatial software. These agentic AI applications act as partners to plan, simplify, and execute complex workflows. Knowing where to start can be challenging for new users. To this end, we developed three new quick guides to... Read More >

Introducing NISAR Data Support

Introducing NISAR Data Support

6/5/2026

The release of ENVI® SARscape 6.3 in April 2026 includes preliminary support for NASA-ISRO SAR (NISAR) data. The NISAR mission is a joint Earth-observing satellite project between NASA and the Indian Space Research Organization designed to monitor changes in the planet’s land and ice surfaces using advanced radar imaging. It... Read More >

Monitoring Illegal Mining in the Amazon: Turning Persistent Data Into Actionable Insight

Monitoring Illegal Mining in the Amazon: Turning Persistent Data Into Actionable Insight

5/28/2026

Illegal mining over decades has constituted one of the most persistent and complex socio-environmental problems in the Brazilian Amazon. In recent years, with the increasingly intensive use of mechanized extraction, the associated environmental impacts—such as deforestation, intense soil disturbance, river siltation, and mercury... Read More >

1345678910Last
23113 Rate this article:
3.3

ENVI Extensions: Getting notifications from ENVI ROIs

Anonym

A recent project I worked on required an ENVI extension to respond ROI changes made in the ENVI Layer Manager.   Fortunately, ENVI provides a mechanism that allows an object to do this.  First, the object must be added to the list of observers for each ROI layer.  The following command provides access to these layers:

IDLcf$Get , /INCLUDE_VIS_CHILDREN, VIS_LAYERS=oVisLayers

The variable oVisLayers will contain all visible layers present in the ENVI display.  To get only the ROIs, loop through its contents looking for any instances of IDLcfVisROINative.  When one is encountered the object can be added to the ROI layer’s list of observers using the following:

void = oVisLayers[i]-> AddObserver (self)

Now that the object has been added to the list of observers an OnNotify method must be added.  Any notifications from the ROI layers will be sent to this method.

function my_class ::OnNotify, oSubject, strMsg, strArg

The input parameters are:\

  • oSubject – A reference to the ENVI object sending the notification
  • strMsg – A string containing the name of the notification (e.g. SETPROPERTY)
  • strArg – A string containing additional notification information (e.g. HIDE)

Here is a stand-alone example that demonstrates setting up an object to receive and act on notifications from ROIs in the ENVI Layer Manager:

;##############################################################################

; This example demonstrates how to get notifications from ENVI when changes are

; made to ROIs in the Layer Manager.

;##############################################################################

;------------------------------------------------------------------------------

;+

; Event handler used by XMANAGER

;

; :Params:

;   sEvent: in, required, type="struct"

;     An IDL event structure

;-

pro roi_demo_event, sEvent

  widget_control, sEvent.top, GET_UVALUE=oRoiDemo

  oRoiDemo->Event, sEvent

end

;------------------------------------------------------------------------------

;+

; Checks ENVI for any ROIs.  DIsplays all of the ROIs found in the message

; text box.

;

; :Keywords:

;   PREFIX: in, optional, type="string"

;     A string or string array of text to be added to the beginning of the ROI

;     message.

;-

pro roi_demo::CheckROIs, $

  PREFIX=prefix

  compile_opt idl2, logical_predicate

  IDLcf$Get, /INCLUDE_VIS_CHILDREN, VIS_LAYERS=oVisLayers

  name = []

  for i = 0, n_elements(oVisLayers)-1 do begin

    if isa(oVisLayers[i], 'IDLcfVisROINative') then begin

      void = oVisLayers[i]->AddObserver(self)

      oROI = oVIsLayers[i]->GetParameter('ROI')

      if obj_valid(oROI) then begin

        name = [name, oROI.name]

      endif

    endif

  endfor

  if (n_elements(prefix) EQ 0) then prefix = 'ROIs found:'

  str = [prefix,(n_elements(name) GT 0) ? name : 'No ROIs found']

  widget_control, widget_info(self.tlb, FIND_BY_UNAME='text_message'), SET_VALUE=str

end

;------------------------------------------------------------------------------

;+

; Creates a dialog for displaying information regarding the ENVI ROIs

;-

pro roi_demo::Dialog

  compile_opt idl2, logical_predicate

  e = envi(/CURRENT)

  self.tlb = widget_base(/COLUMN, /FLOATING, GROUP_LEADER=e.widget_id, $

    TITLE='ENVI ROI Demo')

  xSize = 100

  wLabel = widget_label(self.tlb, /ALIGN_LEFT, VALUE='Notification Information')

  wText = widget_text(self.tlb, UNAME='text_params', XSIZE=xSize, YSIZE=3)

  wLabel = widget_label(self.tlb, /ALIGN_LEFT, VALUE='ROI Information')

  wText = widget_text(self.tlb, UNAME='text_message', XSIZE=50, YSIZE=10)

  wBase = widget_base(self.tlb, /ALIGN_RIGHT, /ROW)

  wButton = widget_button(wBase, UNAME='check_roi', VALUE='Check ROIs')

  widget_control, self.tlb, /REALIZE, SET_UVALUE=self

  self->CheckROIs

  xmanager, 'roi_demo', self.tlb, /NO_BLOCK

end

;------------------------------------------------------------------------------

;+

; Event handler for the ROI demo's dialog

;

; :Params:

;   sEvent: in, required, type="struct"

;     An IDL event structure

;-

pro roi_demo::Event, sEvent

  compile_opt idl2, logical_predicate

  case widget_info(sEvent.id, /UNAME) of

    'check_roi': self->CheckROIs

    else: print, widget_info(sEvent.id, /UNAME)

  endcase

end

;------------------------------------------------------------------------------

;+

; Lifecycle method for initializing the object

;

; :Returns:

;   1 if the object initializes successfully and 0 otherwise

;-

function roi_demo::Init, $

  _REF_EXTRA=refExtra

  compile_opt idl2, logical_predicate

  if (~self->IDLmiObserver::Init(_EXTRA=refextra)) then begin

    print, 'Failed to initialize IDLmiObserver'

    return, 0

  endif

  return, 1

end

;------------------------------------------------------------------------------

;+

; This method is for receiving notifications from the notifiers for which this

; class is an observer.

;

; :Returns:

;   1

;

; :Params:

;   oSubject: in, required, type="objref"

;     The ENVI object that is sending the notifications

;   strMsg: in, required, type="string"

;     The notification string (e.g. SETPROPERTY)

;   strArg: in, required, type="string"

;     A string containing additional notification information (e.g. HIDE)

;-

function roi_demo::OnNotify, oSubject, strMsg, strArg

  compile_opt idl2, logical_predicate

  oSubject->GetProperty, NAME=name

  help, oSubject, OUTPUT=strHelp

  widget_control, widget_info(self.tlb, FIND_BY_UNAME='text_params'), $

    SET_VALUE=[strHelp, 'STRMSG: '+strMsg, 'STRARG: '+strArg]

  str = ''

  case strupcase(strMsg) of

    'ADDITEMS': begin

      str = ['Adding a new ROI','Press Check ROIs when finished']

    end

    'REMOVEITEMS': begin

      self->CheckROIs, PREFIX=['ROI has been removed','Remaining ROIs:']

      return, 1

    end

    'ROI_DEFINITION_CHANGE': begin

      str = name+' has been updated'

    end

    'SETPROPERTY': begin

      case strupcase(strArg) of

        'COLOR': begin

          oROI = oSubject->GetParameter('ROI')

          oROI->GetProperty, COLOR=color

          str = name+' color changed to '+strjoin(strtrim(fix(color),2),',')

        end

        'HIDE': begin

          oSubject->GetProperty, HIDE=hide

          str = name+' has been '+(hide ? 'hidden' : 'shown')

        end

        else:

      endcase

    end

    else: print, 'MESSAGE: '+strMsg

  endcase

  wText = widget_info(self.tlb, FIND_BY_UNAME='text_message')

  widget_control, wText, SET_VALUE=str

  return, 1

end

;------------------------------------------------------------------------------

;+

; Class structure definition

;

; :Inherits:

;   IDLmiObserver

;  

; :Fields:

;   tlb: This widget ID of the dialog's top level base.

;-

pro roi_demo__define

  compile_opt idl2, logical_predicate

  void = {roi_demo           $

   

    , inherits IDLmiObserver $

    , tlb  : 0L              $

   

      }

end

;------------------------------------------------------------------------------

;+

;-

pro roi_demo

  compile_opt idl2, logical_predicate

  e = envi(/CURRENT)

  if ~isa(e, 'envi') then begin

    e = envi()

    eView = e->GetView()

    file = Filepath('qb_boulder_msi', ROOT_DIR=e.root_dir, SUBDIRECTORY=['data'])

    eRaster = e->OpenRaster(file)

    eLayer = eView->CreateLayer(eRaster)

    file = Filepath('qb_boulder_roi.xml', ROOT_DIR=e.root_dir, SUBDIRECTORY=['data'])

    eROI = e->OpenROI(file)

    nROI = n_elements(eROI)

    eLayerROI = objarr(nROI)

    for i = 0, nROI-1 do begin

      eLayerROI[i] = eLayer->AddROI(eROI[i])

    endfor

  endif

  oROIDemo = obj_new('roi_demo')

  oROIDemo->Dialog

end

1 comments on article "ENVI Extensions: Getting notifications from ENVI ROIs"

Avatar image

Mobit Solutions

I did not understand the program in the middle. I'll go through it again and I'll definitely try this in my seo company.

Please login or register to post comments.