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!



From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

From Image to Insight: How GEOINT Automation Is Changing the Speed of Decision-Making

4/28/2025

When every second counts, the ability to process geospatial data rapidly and accurately isn’t just helpful, it’s critical. Geospatial Intelligence (GEOINT) has always played a pivotal role in defense, security, and disaster response. But in high-tempo operations, traditional workflows are no longer fast enough. Analysts are... Read More >

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

Thermal Infrared Echoes: Illuminating the Last Gasp of a Dying Star

4/24/2025

This blog was written by Eli Dwek, Emeritus, NASA Goddard Space Flight Center, Greenbelt, MD and Research Fellow, Center for Astrophysics, Harvard & Smithsonian, Cambridge, MA. It is the fifth blog in a series showcasing our IDL® Fellows program which supports passionate retired IDL users who may need support to continue their work... Read More >

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

A New Era of Hyperspectral Imaging with ENVI® and Wyvern’s Open Data Program

2/25/2025

This blog was written in collaboration with Adam O’Connor from Wyvern.   As hyperspectral imaging (HSI) continues to grow in importance, access to high-quality satellite data is key to unlocking new insights in environmental monitoring, agriculture, forestry, mining, security, energy infrastructure management, and more.... Read More >

Ensure Mission Success With the Deployable Tactical Analytics Kit (DTAK)

Ensure Mission Success With the Deployable Tactical Analytics Kit (DTAK)

2/11/2025

In today’s fast-evolving world, operational success hinges on real-time geospatial intelligence and data-driven decisions. Whether it’s responding to natural disasters, securing borders, or executing military operations, having the right tools to integrate and analyze data can mean the difference between success and failure.... Read More >

How the COVID-19 Lockdown Improved Air Quality in Ecuador: A Deep Dive Using Satellite Data and ENVI® Software

How the COVID-19 Lockdown Improved Air Quality in Ecuador: A Deep Dive Using Satellite Data and ENVI® Software

1/21/2025

The COVID-19 pandemic drastically altered daily life, leading to unexpected environmental changes, particularly in air quality. Ecuador, like many other countries, experienced significant shifts in pollutant concentrations due to lockdown measures. In collaboration with Geospace Solutions and Universidad de las Fuerzas Armadas ESPE,... Read More >

1345678910Last
«May 2025»
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
15273 Rate this article:
No rating

Simplifying Code Libraries and Object Access By Developing Static Methods

Anonym

Another new feature in IDL 8.3 is the ability to create static methods on classes. A static method is a method, either a procedure method or function method, which can be called from outside the class without needing an instance of the class. They can be called using the "dot" syntax, and, from the outside, they work just like regular IDL routines or functions. There are a number of potential uses for static methods. This article will discuss grouping library routines and will also discuss easy access to singleton object operations. To define a method as static, add 'static' to the method's COMPILE_OPT statement.

Static methods can make code libraries much easier to develop and manage by allowing routines to be grouped into categories. IDL has already made some of its built-in class methods static, such as Clipboard.

Prior to IDL 8.3, every user-written helper routine either needed to be in its own file or else the full file in which it is located needed to be compiled before it could be used. Here is an example of a pre-IDL8.3 file that contains multiple helper routines:

PRO helper1
  
  PRINT, 'Helper 1 was called.'
  
END

PRO helper2

  PRINT, 'Helper 2 was called.'

END

PRO helper_routines

; This is a placeholder routine.

END

In order to call either helper1 or helper2, the caller must first call RESOLVE_ROUTINE, 'helper_routines'; otherwise an error would occur. By grouping these routines into static methods, however, IDL will automatically compile the methods when needed, provided that the file is in IDL's path, and the user does not need to manually resolve them. Here is an example of grouping the helpers into a class:

PRO helper_class::helper1
  COMPILE_OPT static

  PRINT, 'Helper 1 was called'

END


PRO helper_class::helper2
  COMPILE_OPT static

  PRINT, 'Helper 2 was called'

END

PRO helper_class__define

  !null = {helper_class, $
    INHERITS IDL_Object}

END

For purposes of grouping routines, there will never be a need to create an instance of the class. Therefore, this class does not need an Init method; only the class definition is needed.

To call one of these routines, use the following syntax:

helper_class.helper1

and IDL will compile and run the routine. Not only does grouping these helper routines offer convenience of a common category name, it also helps prevent namespace conflicts. For example, you could create a second helper class, such as 'helper_class2' that also has a method called 'helper1', and there would not be a conflict between the two methods because they are part of different classes.

 

A second practical use for static methods is to provide easy access to singleton classes. In this example, there is a class called 'IDLDataPoint', and only one of these classes is ever going to be instanciated throughout the application. This class is stored in an application-wide common block, and its properties and methods need to be used in many parts of application.

Prior to IDL 8.3, any routine that needed to access this class must retrieve it out of the common block. However, in IDL 8.3, the object's methods can be made static (this includes GetProperty and SetProperty), allowing them to be called without having a direct reference to the object, and the only place where the work of retrieving the reference can be done within the method. The main trick to doing this is to call OBJ_VALID on self and then call the method recursively. Here is an example of the IDLDataPoint class:

FUNCTION IDLDataPoint::Init
  
  self.name = 'IDL Data Point'
  self.value = 5L

  RETURN, 1

END


PRO IDLDataPoint::GetProperty, NAME=name, VALUE=value
  COMPILE_OPT static

  IF ~OBJ_VALID(self) THEN BEGIN
    COMMON IDLDataPoint_Common, dataPointObj
    dataPointObj.GetProperty, NAME=name, VALUE=value
    RETURN
  ENDIF
  
  IF ARG_PRESENT(name) THEN BEGIN
    name = self.name
  ENDIF
  
  IF ARG_PRESENT(value) THEN BEGIN
    value = self.value
  ENDIF

END

PRO IDLDataPoint::SetProperty, NAME=name, VALUE=value
  COMPILE_OPT static

  IF ~OBJ_VALID(self) THEN BEGIN
    COMMON IDLDataPoint_Common, dataPointObj
    dataPointObj.SetProperty, NAME=name, VALUE=value
    RETURN
  ENDIF
  
  IF N_ELEMENTS(name) GT 0 THEN BEGIN
    self.name = name
  ENDIF
  
  IF N_ELEMENTS(value) GT 0 THEN BEGIN
    self.value = value
  ENDIF
  
END

FUNCTION IDLDataPoint::MultiplyValue, multiplier
  COMPILE_OPT static
  
  IF ~OBJ_VALID(self) THEN BEGIN
    COMMON IDLDataPoint_Common, dataPointObj
    RETURN, dataPointObj.MultiplyValue(multiplier)
  ENDIF
  
  RETURN, multiplier * self.value
  
END

PRO IDLDataPoint__Define

  !null = {IDLDataPoint, $
    inherits IDL_Object, $
    name:'', $
    value:0L}
    
END

 

Create the class and store it in the common block with this routine:

PRO create_datapoint_class

  COMMON IDLDataPoint_Common, dataPointObj
  
  dataPointObj = OBJ_NEW('IDLDataPoint')

END

Now, without ever needing to get the IDLDataPoint class’s instance, you can do everything with this object that you could if you had an instance. Here is some code that shows property access and using a method:

PRINT, IDLDataPoint.NAME

IDL prints:

IDL Data Point

PRINT, IDLDataPoint.VALUE

IDL prints:

5

IDLDataPoint.VALUE=6

result = IDLdataPoint.MultiplyValue(4)

PRINT, result

IDL prints:

24

Thank you for reading. I hope this information is helpful.

Please login or register to post comments.