GeoDMS through Python
GeoDMS and Python can be combined in three different ways. Which one fits best depends on who is “in charge” (Python or the GeoDMS) and on whether the two need to share data in-process or through data files.
| # | Architecture | Who drives | Data exchange |
|---|---|---|---|
| 1 | Run the GeoDMS as a separate process from Python | Python | data files (the GeoDMS reads/writes its configured storages) |
| 2 | Run Python as a separate process from within the GeoDMS | GeoDMS | data files (Parquet / Csv) |
| 3 | Use the GeoDMS Python bindings (in-process) | Python | in-process, through the geodms module |
1. Run the GeoDMS as a separate process from Python
Python orchestrates the workflow and calls the command line tool GeoDMSRun (GeoDmsRun.exe) to let the GeoDMS update one or more items of a configuration. The GeoDMS reads its inputs and writes its results to the files/databases configured as storages (see Data source); Python reads those results back.
This requires no GeoDMS-specific Python code and keeps the two processes fully isolated.
import subprocess
exit_code = subprocess.call([
r"C:\Program Files\ObjectVision\GeoDms\GeoDmsRun.exe",
r"/L", r"C:\tmp\run.log", # write a log file
r"C:\prj\my_project\cfg\model.dms", # the configuration
r"/export/result" # the item (path relative to the desktop root) to update
])
if exit_code != 0:
raise RuntimeError(f"GeoDmsRun failed with exit code {exit_code}")
# now read the file that /export/result was configured to write (e.g. a .parquet or .csv)
See GeoDMSRun and User Guide GeoDMS RUN for the available command line options.
2. Run Python as a separate process from within the GeoDMS
The GeoDMS drives the workflow: it writes an input file, starts a Python script on it, and reads the script’s output back — all triggered automatically the moment the output item is requested. This is useful when a calculation is easier (or only possible) in Python, but it should fit transparently inside a GeoDMS configuration.
The mechanism combines three features:
- write the input as a typed, fast Parquet file (see Parquet);
- start the script with Exec_ec, capturing its ExitCode;
- read the output, with the ExitCode woven into the output StorageName so the read waits until the script has finished.
A worked end-to-end example (write input → run script → read output) is documented on the Exec_ec page. The conditional, lazy triggering of such a script — only running it when its result is actually needed — is described on the Indirect-expression page.
Relevant pages:
- Exec_ec — start the script and gate the read on its ExitCode
- Parquet — exchange typed tabular data with Python (pandas / pyarrow), and relate the imported domain back to an existing domain
- Indirect-expression — only calculate (and run) what is needed
3. Use the GeoDMS Python bindings (in-process)
The geodms Python module embeds the GeoDMS engine inside the Python process. Python can then load a configuration, navigate the item tree, change expressions, update items and read values back without starting a separate process. It can also build a configuration in memory, without a model script, and set parameter and attribute values. The module is installed with pip install geodms, and the GeoDMS setups contain it as well; Python Bindings describes both ways and the full API, with examples.
example usage
Adapted from python/tst/UnitTests.py, after pip install geodms:
from geodms import *
# initialise the engine and load a configuration
engine = Engine()
config = engine.load_config('basic_data_test.dms')
# navigate the item tree from the root
root = config.root()
param_item = root.find("/parameters/test_param")
print(param_item.is_null()) # False if found
# find returns a null item for non-existent paths
missing = root.find("/does/not/exist")
print(missing.is_null()) # True
# change an expression and (re)calculate a dependent result
param_item.set_expr("3b")
result_item = root.find("/export/IntegerAtt")
result_item.update() # updates the item and writes its storage, if configured