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!



Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

Not All Supernovae Are Created Equal: Rethinking the Universe’s Measuring Tools

6/3/2025

Rethinking the Reliability of Type 1a Supernovae   How do astronomers measure the universe? It all starts with distance. From gauging the size of a galaxy to calculating how fast the universe is expanding, measuring cosmic distances is essential to understanding everything in the sky. For nearby stars, astronomers use... Read More >

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

Using LLMs To Research Remote Sensing Software: Helpful, but Incomplete

5/26/2025

Whether you’re new to remote sensing or a seasoned expert, there is no doubt that large language models (LLMs) like OpenAI’s ChatGPT or Google’s Gemini can be incredibly useful in many aspects of research. From exploring the electromagnetic spectrum to creating object detection models using the latest deep learning... Read More >

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 >

1345678910Last
8924 Rate this article:
No rating

Implicit Get/SetProperty calls in user-defined classes, part II

Anonym

In this post, I showed a demonstration of how to use the implicit Get/SetProperty call allowed by subclasses of IDL_Object, using existing Object Graphics classes as the basis. Here, I’d like to go a little further: I’ll write a class that inherits from IDL_Object and implements its own Get/SetProperty methods, then show how the implicit call works with them. The class Integer represents a single long integer value. Start with the class data definition, nothing that we inherit from IDL_Object:

pro integer__define
   compile_opt idl2

   !null = {integer, inherits idl_object, value:0L}
end

Recall that to work seamlessly with IDL’s calling mechanism, this routine should be the last in the file and its methods should be listed before/above it in the file. Next, the Init method, where the user can initialize an Integer to a value (otherwise, the default value of 42 is used):

function integer::init, value=v
   compile_opt idl2

   self.value = ~isa(v, /number) || ~isa(v, /scalar) ? 42L : v
   return, 1
end

Note that, counter to standard technique, it’s not necessary to call IDL_Object::Init from here. For simplicity (and because there’s nothing to clean up), I’ll not write a Cleanup method for this class. Next, the GetProperty and SetProperty methods, which are straightforward:

pro integer::getproperty, value=v
   compile_opt idl2

   if arg_present(v) then v = self.value
end 

pro integer::setproperty, value=v
   compile_opt idl2

   if v ne !null then self.value = v
end

At this point, let’s stop and create an instance of Integer, int1:

IDL> int1 = integer(value=5)

and then perform a few simple diagnostics on it to check that everything is working correctly:

IDL> help, int1
INT1            OBJREF    = 
IDL> print, int1

IDL> print, isa(int1, 'Integer')
    1

Now, get the value of the Integer int1. Prior to IDL 8, this required an explicit call to Integer::GetProperty, like this:

IDL> int1->getproperty, value=v1
IDL> print, v1
       5

whereas IDL 8 allows an implicit call to GetProperty when using the dot “.” operator:

IDL> print, int1.value
       5

Note that the keyword name in the GetProperty formal parameter list is what is used in the implicit call. Had, for example, the keyword instead been named TH3_$VALUE, the implicit call to GetProperty would be int1.th3_$value. Analogous syntax holds for the Integer::SetProperty method. For example, use the IDL 8 syntax to change the value of int1 to 7:

IDL> int1.value = 7
IDL> print, int1.value
       7

The implicit calls to Get/SetProperty only work for subclasses of IDL_Object. Also, this does not change the fact that instance variables in IDL are protected. In my opinion, this syntax is more elegant and easier to use than an explicit call to a Get- or SetProperty method. But we can go further! What I’ll do next overlaps with the description and example of operator overloading that Mike Galloy gave some time ago, but it feels natural to extend the present example a bit further. Here, we’ll overload the PRINT procedure and the plus sign “+” for Integer. First, overload PRINT by overriding the IDL_Object::_overloadPrint method:

function integer::_overloadprint
   compile_opt idl2

   return, self.value
end

Now when we print an Integer we get its value instead of some cryptic reference to an object heap variable:

IDL> print, int1
       7

Next, overload the plus operator “+” so that we can add two Integers:

function integer::_overloadplus, left, right
   compile_opt idl2

   if ~isa(left, obj_class(self)) || ~isa(right, obj_class(self)) then $
      return, obj_new() $
   else $
      return, integer(value=left.value + right.value)
end

The parameters left and right are inherited from the IDL_Object::_overloadPlus method: they represent the two Integer objects to be added. They’re tested to make sure they’re Integers. If they are, the implicit GetProperty call is used to get their values, the sum of which is used to make a new Integer, which is returned. For example, define another Integer, int2, and add it to int1 to get a third Integer, int3:

IDL> int2 = integer(value=3)
IDL> int3 = int1 + int2
IDL> print, int3
       10

This operation wouldn’t be possible without operator overloading. A complete list of operators than can be overloaded in a user-defined class can be found in the IDL Help; search for “overload.” You can download the complete, IDLdoc-ed code for this Integer class from here.

Please login or register to post comments.