Skip to main content

I am relatively new to FME and have been attempting to process data which I would typically do with MapBasic. I have gotten so far but have gotten stuck at the point where I would typically run a loop in MapBasic

 

When it gets to the point marked ‘ok to here’ The data is sorted and grouped by asset

 

1.     What I’m attempting to do is loop for every asset group i.e. asset 12 in the example below and then for RTC, FCD and NoPumps sum the number in the group

2.     Update the row where the count = 1 i.e. RTC = 0 FCD=0 NoPUMPs=2

3.     Then discard the remaining lines i.e. 2-7 in the example 

 

 

i.e.

 

 

After repeating for every Asset Group I should then end up with a single line, 10,929, for each Asset, containing the number of Pumps, FCD’s etc  

 

 

 

 

 

 

 In MapBasic I would simply do this with a few lines of code but can’ replicate with FME.

 

Select max(asset) from Data into iA

 

   Fetch first from iA

      iAssets = iA.Col1

         Close Table iA

 

 

For iLoop1=1 to iAssets

   Select asset, _count, CommonName, sum(RTC),sum(FCD),sum(Pump) from Data where asset=iLoop1 into tTMP

      Fetch first from tTMP

         iRTC =tTMP.Col4

         iFCD =tTMP.Col5

         iPump=tTMP.Col6

             Close Table tTMP

 

   Select * from Data where asset=iLoop1 and _count=1 into tUpdate

 

   Update tUpdate set RTC = iRTC, FCD = iFCD, Pump = iPump 

      Close Table tUpdate

 

Next 

 

 I have been pointed in the direction of a workspace runner but don’t see how this would work. Any assistance would be greatly appreciated.

 

Richard

Cant you just use the aggregator transformer with a group by on the "asset" attribute.

You can set the accumulation mode to "Use Attributes From One Feature" and then chose to sum the "RTC","FTC", and "NoPUMPs" attribute.

Generally you don't need to loop in FME, and if you think you might need to you can still use cloners. Looping in FME is very resource heavy and very difficult to set up if you don't have a lot of experience.


With a programming mind set going into FME is a bit of a mind shift. It helps to think about iterating over a dataset. And using features or rows in a table to drive iterations. Each instance of a workspace (running fme) can be called from another workspace (or FME Server job submitter) to "act/iterate" on a dataset or subset of a dataset. Think of a workspace as a forked process that can be run async or in sequence. Custom transformers can be thought of as reusable logic (sub routines/methods) that act on one feature (or object) at a time. Hope this helps.


Thank you that worked a treat, as you say a different mind shift. Thanks again


Reply