2

I have an FME workspace which has a number of different workspaceRunner transformers. The first workspaceRunner launches a workspace which buffers a pipeline and outputs the bounding coordinates to a CSV file.

I then have a python caller which reads the CSV to get the bounding coordinates and save them as global variables.

enter image description here

The code of the Python Script looks like this:

import fmeobjects
import csv

# Template Function interface:
def processFeature(feature):
    global XMIN
    global XMAX
    global YMIN
    global YMAX


    outputDirectory = FME_MacroValues['Output_Directory']
    csvPath = outputDirectory + '\\Buffer Bounds.csv'
    coordlist = []

    with open(csvPath, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter = ',')
        for row in reader:
            coordlist.append(row)

    XMIN = float(coordlist[0][0])
    XMAX = float(coordlist[0][2])
    YMIN = float(coordlist[0][3])
    YMAX = float(coordlist[0][4])    

    print XMIN, XMAX, YMIN, YMAX
    pass

# Template Class Interface:
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        self.pyoutput(feature)
    def close(self):
        pass

After the PythonCaller, I have four VariableRetriever transformers which get the values of XMIN, XMAX, YMIN, YMAX and save them as attributes.

That is then connected to a workspaceRunner transformer. The parameters for the bounding box are passed to the next workspace and are used to define the Search Envelope Coordinates for the File Geodatabase.

enter image description here

enter image description here

My problem is that these variables are somehow not getting passed to the attributes. Am I using the variableRetriever transformers correctly? I have read on some FME forums that you can use them this way. I've declared them as global variables.

1

Turns out, I didn't need to use a VariableRetriever or VariableSetter transformer. I first create the attributes that will hold the bounds:

enter image description here

Then I pass that to the PythonCaller and expose those attributes. The code looks like this:

import fmeobjects
import csv

# Template Function interface:
def getBounds(feature):
    global XMIN
    global XMAX
    global YMIN
    global YMAX


    outputDirectory = FME_MacroValues['Output_Directory']
    csvPath = outputDirectory + '\\Buffer Bounds.csv'
    coordlist = []

    with open(csvPath, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter = ',')
        bounds = reader.next()

    XMIN = float(bounds[0])
    XMAX = float(bounds[1])
    YMIN = float(bounds[2])
    YMAX = float(bounds[3])    

    feature.setAttribute("_xmin", XMIN)
    feature.setAttribute("_ymin", YMIN)
    feature.setAttribute("_xmax", XMAX)
    feature.setAttribute("_ymax", YMAX)


    print XMIN, XMAX, YMIN, YMAX
    pass

# Template Class Interface:
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        self.pyoutput(feature)
    def close(self):
        pass

And the dialog box looks like this:

enter image description here

I can then pass those attributes as parameters to other WorkspaceRunners.

Now, my workspace runs in minutes instead of 2.5 hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.