Skip to main content

Problem in short:

I have a lot of points which some has identical coordinates. PointOnPointOverlayer does this for me and store the “twins” in a list name. Now I want to use a Pythoncaller to loop through the list of each feature and figure out if some or none of the twin attributes has a value that should update the the major feature. The problem is that I cant seem to reach the list variable created in PointOnPointOverlayer from the Pythoncaller. 

It seems to be exposed when running with feature cache and checking output from PointOnPointOverlayer. What’s the magic for reading the list, looping throug it and check the attribute values?

 

Tried this example code from the PythonCaller just to see if I could reach the list but can’t see anything: 

 

Is there no message in the log file?

The example should write key: bla, value: blabla to the Log window.

 


An FME List is more like a Python Dictionary, in Python a list is a group of values, where as in FME a list is a group of keys and their values.

In your first line, that will evaluate to ‘None’ so will never pass the If clause.

To get a list Attr, you need to do something like:

foo = feature.getAttribute('__list{}.attr1')

bar = feature.getAttribute('__list{}.attr2')

for f, b in zip(foo, bar):
print(f, b)

You can then iterate over them both at the same time using zip - only works if lists are the same length


There are lots of transformers that work on lists, you may easily have missed the right transformer for what you want to accomplish. Maybe this tutorial can be of help:

https://support.safe.com/s/article/working-with-list-attributes-tutorial


Thanks for the response!

I managed to solve the problem, but to me it doesn’t seem like the attributes that I access with getAttribute are typed as an ordinary Python lis/dictionaryt. It’s more like the list and dictonary is converted to pure strings when it enters the PyhonCaller. That’s what confused me when I read different examples on the internet. When I read 'dupl_attr{0}.Fritext' I thought that was a list when it just was a simple string. 

 

The only way for me to solve the problem was to loop the number of entrys in the “list”. A number that I got through another integer value in the feature. Then create the feature name I wanted to access by creating a string which at first glance, looks like a list reference, but in fact is just a plain string. 

 

Example: 

        altValues = ]
        overlaps = feature.getAttribute('_overlaps')
        for x in range(overlaps):
            itemValues =  {}
            for item in self.featAttr:
                itemValues.update({item:feature.getAttribute('dupl_attr{' + str(x) + '}.' + item)})
            altValues.append(itemValues)

 

Where self.featAttr is a list created inside Python caller with names of the feature attributesI want to check. For example: s'Fritext','MarkTyp','MatOrg']

Second last row in the example creates a string that can look like this: 'dupl_attr{0}.Fritext' which is not a list type but just a string that looks like a list :)

Maybe there are other solutions but I wanted to solve this in a Pythoncaller instead of an ordinary transformer. 

 


Reply