X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



80 Rate this article:
No rating

Passing named structures between IDL and Python using the IDL Python bridge

Named structures cannot be passed directly between IDL and Python when using the IDL-Python bridge. Therefore, the transfer of named structures from IDL to Python, and vice versa, must be handled manually.

One Python equivalent of an IDL named structure is a dataclass. The first example below shows how to create an IDL named structure and pass it to Python to create the corresponding Python dataclass, using the Python-to-IDL bridge. The second example demonstrates the reverse process, that is, how to recreate an IDL named structure from a Python dataclass, still using the Python-to-IDL bridge.

 

Launching the Python to IDL bridge (Windows-based example):

(py313) C:\Users\joeuser>python

Python 3.13.15 | packaged by Anaconda, Inc. | (main, Aug 14 2026, 17:17:48) [MSC v.1942 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> sys.path.append('C:\\Program Files\\NV5\\ENVI62\\IDL92\\lib\\bridges')

>>> from idlpy import *

IDL 9.2.0 (Win32 x86_64 m64).

(c) 2025, NV5 Geospatial Solutions, Inc.

Licensed for use by: NV5 Geospatial Internal Use Only

License: xxxxxxx-internal

>>> 

 

Creating an IDL named structure in IDL:

>>> IDL.run('a={test_str,aa:2,bb:2.0,st:"str"}')

>>> IDL.run('st_name=typename(a)')

>>> IDL.run('help,a')

** Structure TEST_STR, 3 tags, length=24, data length=22:

   AA              INT              2

   BB              FLOAT           2.00000

   ST              STRING    'str'

>>> IDL.run('print,a.aa')

       2

>>> IDL.run('print,a.bb')

      2.00000

>>> IDL.run('print,a.st')

str

>>>

 

Example 1: Converting an IDL named structure to a Python dataclass, using the Python-to-IDL bridge:

>>> a=IDL.a

>>> st_name=IDL.st_name

>>> print(st_name)

TEST_STR

>>> print(a)

OrderedDict({'AA': np.int16(2), 'BB': np.float32(2.0), 'ST': 'str'})

>>> from dataclasses import make_dataclass

>>> fields = [(k, type(v)) for k, v in a.items()]

>>> StructClass = make_dataclass(st_name, fields)

>>> obj = StructClass(**a)

>>> print(obj)

TEST_STR(AA=np.int16(2), BB=np.float32(2.0), ST='str')

>>> print(obj.AA)

2

>>> print(obj.BB)

2.0

>>> print(obj.ST)

str

>>> 

 

Example 2: Converting a Python dataclass to an IDL named structure, using the Python-to-IDL bridge:

>>> from dataclasses import fields

>>> from collections import OrderedDict

>>> od = OrderedDict((f.name, getattr(obj, f.name)) for f in fields(obj))

>>> print(od)

OrderedDict({'AA': np.int16(2), 'BB': np.float32(2.0), 'ST': 'str'})

>>> struct_name = obj.__class__.__name__

>>> IDL.struct=od

>>> IDL.name_st=struct_name

>>> IDL.run('struct = create_struct(name=name_st, struct.toStruct())')

>>> IDL.run('help,struct')

** Structure TEST_STR, 3 tags, length=24, data length=22:

   AA              INT              2

   BB              FLOAT           2.00000

   ST              STRING    'str'

>>> IDL.run('print,struct.AA')

       2

>>> IDL.run('print,struct.BB')

      2.00000

>>> IDL.run('print,struct.ST')

str

>>>

 

 

 

---------------------------------------------------------

created by BC (EU) on 9/9/26

reviewed by BC (US) on 9/10/26

Please login or register to post comments.
Featured

IDL and ENVI Agent FAQ

3/17/2026

What are the IDL and ENVI Agents? What can IDL or ENVI Agent help me do? What platforms support IDL... more »

Which Next-Generation License Server version should I install on my system?

10/16/2025

  In general, we recommend installing and using the latest Next-Generation License Server (NGLS)... more »

My Licenses Portal - Users Guide

9/24/2025

  Introduction License Administrators (and Distributors) can view license Original... more »

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade Your ENVI 6.x / IDL 9.x Licenses (including modules)

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »