Extending Spatial Modeler with IMAGINE Command Line Tools

Extending Spatial Modeler from ERDAS IMAGINE with Command Line Tools

With each update to the Spatial Modeler, a tool used for building and running geoprocessing workflows that’s found in select desktop products like ERDAS IMAGINE, we add more traditional remote sensing capabilities as well as vector GIS and point cloud analysis. There are, however, many tools that have not yet been integrated. Fortunately, you may be able to use some of these tools in your spatial model today by harnessing the power of the Command Line operator. You can use this tool to pass simple data (file names, numbers, and strings) to a command line program (even if it might be a third-party command) and then open the output file for further processing.

It is worth noting that unlike the general operation of spatial model operators which pass a streaming currency between them to avoid the need to create temporary intermediate files, using a command-line program is usually limited to File-in, File-out operations. Consequently, use of the Command Line operator usually requires the use of input and output operators to pass geospatial data through it. These can be set up as temporary files which are automatically removed when the model is no longer in use.

The above example shows a spatial model which searches a user-specified directory for images matching a wildcard search, stacks those images into a single multi-band raster, performs simple image segmentation (via the Command Line operator) on the stacked image, calculates the stack mean DN values for all the pixels in each segment, and finally attaches those means as attributes values on an output thematic image.

The steps to using a command line program in Spatial Modeler are as follows:

  1. Drag a Command Line operator into your spatial model.
  2. Double click to open the operator dialog and choose the exe for the command line program you want to use.
  3. Add input ports for the input parameters you wish to set from Spatial Modeler inputs by clicking on the “Add a new input port” button at lower left of the dialog. In the example above, we added a port for the stacked image filename.
  4. Add an output port (by clicking on the “Add a new output port” button toward lower left of the dialog) for the output file name, which, since we want it to be a temporary file, will be defined using the Create Temp Filename operator.
  5. Create the argument string in the Arguments box by manually adding parameters or double clicking on items in the Ports list to add them at the current cursor location.
  6. The arguments in this example read in the image file defined by $input1 and creates the output file defined by $output1 by running image segmentation. The arguments specify to not use edge finding (-doedge 0, which means the subsequent three arguments are ignored) but first smooths the input image (-smoothingtimes 1), and then segments using minimum difference between regions of 20 (-minvd 20), variance factor of 3.5 (-vf 3.5), and all layers via Euclidean Distance (-dt “All Layers” -ue 1). It does not attempt to retain narrow strip segments (-findnarrowstrip 0) and specifies that each segment must be at least 50 pixels in area (-setminsegsize 1 -minsegsize 50). The final argument, -m, is for metering. Note that all these argument could also be defined by adding new input ports to set them via the spatial model, but in this simple example we have left them hardwired.
  7. Close the Command Operator dialog by clicking OK and connect the input and output ports.

When defining the arguments to be passed to the command, care should be taken to cater for strings with spaces in them. For example, the imagesegmentation.exe program has a -dt argument which can have a value of “All Layers” or “Intensity”. The “All Layers” needs to be enclosed in quotes so that the command line parser understands that it represents a single value, not two values of “All” and “Layers” (which would be an invalid input to the program and cause the Command Line operator to fail when executed).

You can find documentation for many ERDAS IMAGINE command line tools by searching the Online Help. This documentation will help you to understand which parameters need to be passed into the command line to generate your desired results. Another approach when using ERDAS IMAGINE programs, which is what we used when setting up the above example, is to bring up the appropriate dialog in ERDAS IMAGINE (e.g. Raster tab > Classification group > Unsupervised menu > Image Segmentation), fill in the arguments you will generally want to use, and then hit Batch. The Batch Editor will present the command that would be issued and you can copy and paste the executable name and its arguments into the Command Line operator for further editing and variablization.

Third-party executables can also be used so long as they ingest and produce file formats which are supported by the Spatial Modeler.

Learn more about the Spatial Modeler on the Hexagon Geospatial Community.