PCI Geomatics Help Center

How can we help you today?

Create a Report File for Geomatica Functions

PCI Geomatics -



This tutorial demonstrates how to use Python to get a Geomatica function to write ancillary (report) information to an ASCII (text) file instead of the default, which prints to terminal.

Figure 1: Geomatica functions default behaviour of printing to terminal (left) vs. writing the same report to a text file using the Report class (right)


Watch this Tutorial




In addition to generating the output product, some of Geomatica’s functions print important ancillary information about the process and output quality that can be used to help your code make useful decisions about what to do next. Ultimately, storing this information in a text file will allow developers to automatically parse the report information for key information to determine what the code should do next. This can improve automation of your workflows.



  • Geomatica 2015 or later installed
  • Python 101 (basic understanding of python coding concepts)
    • try, except, finally statements
    • How to access modules and classes
    • How to call a function
  • Some experience programming with Geomatica (recommended)

Data Package


  • Click Here to download the data required for this tutorial



To demonstrate how to use the Report class to write ancillary information from a Geomatica function to an ASCII (text) file, we will call the MLR function, which creates a report based on information stored in a classification channel. Because the purpose of this tutorial is to teach you how to use the Report class, the starting (input data) will be a classification channel (already computed) and the output will be a classification report, written to a text file.

1. Import necessary modules & setup inputs/outputs


The first step is to import the Geomatica modules we will be calling in this tutorial and setting up the variables that will point to our input file(s) and output file(s).

import os
from pci.mlr import mlr
from pci.nspio import Report, enableDefaultReport

# set input and output files for workflow
working_dir = r'D:\tutorial\report_to_file'  # set this path to the dir where you extracted the tutorial data
classified_image = working_dir + os.sep + 'irvine.pix'
rep_file = working_dir + os.sep + 'MLC_report.txt'

In the above code block, line 2 is used to import Geomatica’s mlr function, which will be generating the report information. By default, like all other Geomatica functions, the report will be printed to the terminal. Line 3 imports the Report class and enableDefaultReport function, which is required to port the report information from mlr to a text file set in your code.

On line 6, working_dir is a variable that contains the path to the directory where your tutorial data is stored. You will need to change this to the directory on your computer where your tutorial data is saved.

2. Setup report file to write to a file & call the Geomatica function(s)


The second and final set of steps requires that you set the text file that will receive the report information and then call Geomatica’s mlr function.


    mlr(file=classified_image, dbic=[6], dbs1=[17, 18, 19, 20, 21, 22, 23, 24])
    # You can run other Geomatica functions before closing the report file, which will append to the end of the rep file

    enableDefaultReport('term')  # this will close the report file

Using Python’s try: and finally: statements, the script will port all ancillary (report) information to a text file. On line 10, you first call the Report.clear() function to clear any report information that may still be in memory. On line 11, you call the enableDefaultReport(rep_file) function and pass the variable that contains the path to the output text file you want the report information written to as its argument. On line 13, call the mlr function and pass the following keyword arguments:

  • file = variable holding the .pix file, which contains the classification image
  • dbic = the channel in the .pix file containing the classification map
  • dbsl = the segment numbers in the .pix file containing the classification signatures, which will assign class names in the report

The mlr function has more reporting options, click on any of the mlr references in this tutorial to open this function’s online help.

Lastly, on line 17, call enableDefaultReport(‘term’) to close the report file.

Have more questions? Submit a request


Powered by Zendesk