table with full filenames

Table containing full filenames.

Loading files from a list of filenames to process them in sequence is a common problem when building large models. In the following examples we will show different techniques that can be used to implement such functionally in a model using Dinamica EGO. Beware that we will just load maps and discard their contents to keep the examples simple. Turning these models into something useful will be left as a exercise to the reader.

First we have to decide how to store the list of filenames. All our examples store the list of filenames in a table mapping unique ids to filenames. Even if Dinamica EGO can use Strings as table keys, it can not iterate over them. To workaround this limitation, we use a unique id as key for each filename and retrieve the corresponding filename later in a loop. Map filenames with lower unique ids are processed before those with higher uniquer id values.

Now we have to decide how to represent the file paths.

Out first attempt to solve that problem stores the whole path for each map in the input table. This approach works but it is far from portable. Moving all maps to a different folder would required redefining the paths of all maps in the table which would be time consuming and error prone.

load files from tables 0

Example storing the full path for each map in a table.

table with filenames

Table containing filenames.

To increase the model portability and facilitate its use in a different computer with a different folder structure, the folder containing the files can be provided by an additional input with type Folder.

Using that philosophy, our next attempt uses a Workdir to merge the Folder name and the filename coming from a table. The merging is performed by the Load Map itself combining data from the Workdir, where the Folder is connected, and the String representing the map filename. The String representing the filename comes from a Get Table Value used to retrieve the row value corresponding to the current unique id.

load files from tables 1

Example using a Workdir to combine the map folder and the map filename.

Another attempt to separate the folder from the map filename explicitly combines the Folder and the filename from the table using a Create String. The format used by the Create String is simply “<s1>/<s2>” where “s1” represents the Folder and “s2” represents the filename.

load files from tables 2

Example using a Create String to combine the map folder and the map filename.

All our previous examples load all files sequentially and can be used in a real model. However, the use of a Workdir brings an additional advantage: it can also be used to load maps stored in a zip archive by simply changing the folder to point to a zip file containing the maps.

Unfortunately, “ers” is one of the few file formats that can not be loaded from a zip archive by Dinamica EGO. For that reason, we are using GeoTiffs in our last example.

load files from tables 3

Example using a Workdir to load maps from a zip archive.

All models used to illustrate the techniques above can be downloaded from here.