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!



Deploy, Share, Repeat: AI Meets the Analytics Repository

Deploy, Share, Repeat: AI Meets the Analytics Repository

10/13/2025

The upcoming release of ENVI® Deep Learning 4.0 makes it easier than ever to import, deploy, and share AI models, including industry-standard ONNX models, using the integrated Analytics Repository. Whether you're building deep learning models in PyTorch, TensorFlow, or using ENVI’s native model creation tools, ENVI... Read More >

Blazing a trail: SaraniaSat-led Team Shapes the Future of Space-Based Analytics

Blazing a trail: SaraniaSat-led Team Shapes the Future of Space-Based Analytics

10/13/2025

On July 24, 2025, a unique international partnership of SaraniaSat, NV5 Geospatial Software, BruhnBruhn Innovation (BBI), Netnod, and Hewlett Packard Enterprise (HPE) achieved something unprecedented: a true demonstration of cloud-native computing onboard the International Space Station (ISS) (Fig. 1). Figure 1. Hewlett... Read More >

NV5 at ESA’s Living Planet Symposium 2025

NV5 at ESA’s Living Planet Symposium 2025

9/16/2025

We recently presented three cutting-edge research posters at the ESA Living Planet Symposium 2025 in Vienna, showcasing how NV5 technology and the ENVI® Ecosystem support innovation across ocean monitoring, mineral exploration, and disaster management. Explore each topic below and access the full posters to learn... Read More >

Monitor, Measure & Mitigate: Integrated Solutions for Geohazard Risk

Monitor, Measure & Mitigate: Integrated Solutions for Geohazard Risk

9/8/2025

Geohazards such as slope instability, erosion, settlement, or seepage pose ongoing risks to critical infrastructure. Roads, railways, pipelines, and utility corridors are especially vulnerable to these natural and human-influenced processes, which can evolve silently until sudden failure occurs. Traditional ground surveys provide only periodic... Read More >

Geo Sessions 2025: Geospatial Vision Beyond the Map

Geo Sessions 2025: Geospatial Vision Beyond the Map

8/5/2025

Lidar, SAR, and Spectral: Geospatial Innovation on the Horizon Last year, Geo Sessions brought together over 5,300 registrants from 159 countries, with attendees representing education, government agencies, consulting, and top geospatial companies like Esri, NOAA, Airbus, Planet, and USGS. At this year's Geo Sessions, NV5 is... Read More >

1345678910Last
«October 2025»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
13668 Rate this article:
3.0

IDL Object Programming: Inherits vs. Contains

Anonym

Last month, I wrote an article titled Overloading Objects in IDL. This article discussed how an object can inherit a class and become a subclass of the inherited class. When an object inherits another class, the object is considered to be one of the parent classes. In the Fancy_List example from last month's blog, this was demonstrated by calling ISA on the Fancy_List and asking IDL if the Fancy_List is a list. IDL reported true.

There are times, however, when inheritance is not appropriate. For instance, I'd like to have my fancy list include a hash, which contains the list's modification history; the hash keys will contain a timestamp of when a change is mode to the list, and the value of the hash will be the latest version of the hash.

In this example, it doesn't make sense for the fancy list to inherit HASH. First, the fancy list should not have the properties and methods of HASH. Additionally, we don't want to say that our fancy list is a hash. Finally, because LIST and HASH are both subclasses of IDL_Object and IDL does not allow IDL_Object to be inherited multiple times, the following line would give an error:

!null = {Fancy_List, inherits List, inherits hash}

% FANCY_LIST is already defined with a conflicting definition.
% 1 Compilation error(s) in module FANCY_LIST__DEFINE.

Instead, the fancy list should contain a hash rather than directly inherit it. The following object definition defines the object with a member variable called "history."

pro Fancy_List__Define

  !null = {Fancy_List, $
    inherits List, $
    history: Object_New() }

end

Note that this only creates a placeholder for the hash. The hash must be defined in the ::Init method.

function fancy_list::Init, _REF_EXTRA=extra

  if (~self.List::Init(_EXTRA=extra)) then return, 0
  
  self.history = OrderedHash()
  
  return, 1
  
end

 

Now, as expected, calling ISA(fl, 'HASH') returns zero.

Updating the member

Each time the list is modified, the hash needs to be updated. Here is an example of the ::Add method that updates the history each time a value is added. 

pro Fancy_List::Add, value, index, _REF_EXTRA=extra

  if ~Isa(value, /NUMBER) then return

  self.List::Add, value, index, _EXTRA=extra
  
  self.history[timestamp()] = self[0:self.Count()-1]

end

(the operation self[0:self.Count()-1], which creates a sub-list of the list containing all elements, is a clever way to duplicate the list)

Similar logic should be added to other modification methods such as ::Remove, ::Move, etc. 
 

Retrieving a member from outside of the object

Now that a fancy list with history can be created using the following call

fl = Obj_New('Fnacy_List')

how is the hash accessed?

The hash can either be a property of the object, or it can be accessed through a separate method. Generally, a property is sufficient unless extra work is needed to be performed on the member before it is passed outside of the object.

pro Fancy_List::GetProperty, MODIFICATION_HISTORY=history, _REF_EXTRA=extra
  
  if (Arg_Present(history)) then begin
    history = self.history
  endif
  
  if (N_Elements(extra) gt 0) then begin
    ; Get any properties not defined in this class from the superclass.
    self.List::GetProperty, _EXTRA=extra
  endif

end

One convenience of using properties is that they can be accessed using the "dot" sytax:

history = fl.MODIFICATION_HISTORY

Modifying a member from outside the class

Similar to accessing a member via GetProperty, it is common to be able to set a member via SetProperty. However, in this example, the history should not be included in SetProperty because it should only be appended from within the object and not from the outside.

One thing a user might want to do to save memory is occasionally clear the history. This is a good example of how a member should be modified via a separate method. Fancy_List::ClearHistory is a good name.

pro Fancy_List::ClearHistory
  
  self.history.Remove, /ALL
  
end

Cleaning up the member

Lastly, it is important to know what to do with member variables when the object that contains it is destroyed. In many cases the contained item will be automatically garbage collected when it falls out of scope, so there is nothing to worry about.

However, it is often good practice to write a ::Cleanup method that handles cleaning up the members. This ensures that no matter where the member gets used outside of the class, where it could potentially get stuck in a circular reference, it will be properly disposed. Additionally, there may be cases where you may want to explicitly cleanup or perform special handling on the member when the object is destroyed. 

Here is an example Cleanup method for Fancy_List:

pro Fancy_List::Cleanup
  
  Obj_Destroy, self.history
  
end

Here is a demonstration of the history being destroyed when the parent object is destroyed:

Obj_Destroy, fl
print, obj_Valid(history)

IDL prints:

   0

 

Please login or register to post comments.